Hello!
I've made grid function for my editor. The problem is that I can't calculate position of object to stay on tile. The position is correct when I zoom object without moving it, but when I move it for greater value than zoom (default: 15px) the position get wrong when zooming the object again. Any help

?
Set Display Mode 1024,768,32
Sync On : Sync Rate 60
#Constant TRUE 1
#Constant FALSE 0
Global Zoom
Global MaxZoom
Global MinZoom
Global xGridTilt
Global yGridTilt
Global xGridTiltCount
Global yGridTiltCount
Global xTilt
Global yTilt
Zoom = 15
MaxZoom = 100
MinZoom = 5
Global LineSize
LineSize = 5
Do
Cls
if controlkey() = 1
inc linesize,1
endif
if upkey() = 1
inc yGridTilt,1
inc yTilt,1
if abs(yGridTilt) > Zoom
yGridTilt = 0
inc yGridTiltCount,1
dec yTilt,1
endif
endif
if downkey() = 1
dec yGridTilt,1
dec yTilt,1
if abs(yGridTilt) > Zoom
yGridTilt = 0
dec yGridTiltCount,1
inc yTilt,1
endif
endif
if leftkey() = 1
inc zoom,1
endif
if rightkey() = 1
dec zoom,1
endif
remstart
xTile = Int((Mousex() - 5) / Zoom)
yTile = Int((Mousey() - 5) / Zoom)
Ink Rgb(200,0,0),0
Box xTile * Zoom- xGridTilt+5 ,yTile * zoom - yGridTilt+5,xtile*zoom + zoom- xGridTilt+5,ytile*zoom+zoom - yGridTilt+5
remend
If Zoom > MaxZoom
Zoom = MaxZoom
Endif
If Zoom < MinZoom
Zoom = MinZoom
Endif
Gosub _UpdateGrid
Ink Rgb(0,0,0),0
Text 5,5,"Zoom: " + Str$(Zoom)
Text 5,20,"yGridTilt: " + Str$(yGridTilt)
Text 5,35,"yTilt: " + Str$(yTilt)
Text 5,50,"Mousex: " + Str$(Mousex())
Text 5,65,"Mousey: " + Str$(Mousey())
Text 5,80,"obj x: " + str$(objx)
Text 5,95,"obj y: " + str$(objy)
Ink Rgb(255,0,0),0
rem this down below is the object, which i want to place on wanted tiles:
xTile = 5
yTile = 10
objx =xTile * Zoom + xTilt
objy = yTile * Zoom + yTilt
Box objx,objy,objx+zoom,objy+zoom
Gosub _UpdateScreen
Sync
Loop
_UpdateGrid:
Ink Rgb(240,240,240),0 : Box LineSize,LineSize,Screen Width() - LineSize,Screen Height() - 200 - LineSize
Ink Rgb(100,100,100),0
Count = 0
For xStep = 0 To Screen Width() Step Zoom
Inc Count,1
Line xStep + xGridTilt,0,xStep + xGridTilt,Screen Height() - 200
Next xStep
For yStep = 0 To Screen Height() - 200 Step Zoom
Inc Count,1
Line 0,yStep + yGridTilt,Screen Width(),yStep + yGridTilt
Next yStep
Return
_UpdateScreen:
Ink Rgb(20,20,20),0 : Box LineSize,Screen Height() - 200,Screen Width() - LineSize,Screen Height() - LineSize
Ink Rgb(50,50,50),0
Box 0,0,Screen Width(),LineSize
Box 0,0,LineSize,Screen Height()
Box Screen Width() - LineSize,0,Screen Width(),Screen Height()
Box 0,Screen Height() - LineSize,Screen Width(),Screen Height()
Box LineSize,Screen Height() - 200 - LineSize,Screen Width() - LineSize,Screen Height() - 200
Return
Happy to having and using DarkBASIC Professional...
