Ask here your questions to get help using GDevelop.
By scott_taylor
#45521 is there anyway to use the grid to snap objects to the base layer e.g. instead of the drag-able object being able to be dragged smoothly i want it so it snaps to grid every 25 pixels (i just dont know how to implement it) any help would be much appreciated
By scott_taylor
#45523 i have done that but when i preview my game it does snap to it the object just takes the position where you release left click
By Glaydur
#45525
Lizard-13 wrote:Search for a "Edit the grid" in the top bar of the Scene tab, you can set the grid size, color, and the "snap to grid" option :)


I think he's asking on how to implement it in his game.
User avatar
By Lizard-13
#45529 Ohhhh... hehe :oops:
Are you talking about the "Draggable Automatism"? Ok, here we go:
Simple Snap-to-grid system
(5.1 KiB) Downloaded 209 times

The snap (in a 32x32 grid) is given by the code:
Code: Select allPosition.X() = 32*(round(Position.X()/32))

So: First divide the position by 32 and round to get the integer for the grid, then multiply by 32 to get the old position rounded
Example:
Code: Select allIf position is 35: 35/32 = 1.09   ==>  round(1.09) = 1  ==>  new position = 32*1 = 32
If position is 70: 70/32 = 2.19   ==>  round(2.19) = 2  ==>  new position = 32*2 = 64
By scott_taylor
#45531 Thanks for that ill have a play around with it and get back to you soon thanks for the help
By scott_taylor
#45533
Lizard-13 wrote:Ohhhh... hehe :oops:
Are you talking about the "Draggable Automatism"? Ok, here we go:
SnapToGrid.rar

The snap (in a 32x32 grid) is given by the code:
Code: Select allPosition.X() = 32*(round(Position.X()/32))

_____________________________________________________________________________________________________________
So: First divide the position by 32 and round to get the integer for the grid, then multiply by 32 to get the old position rounded
Example:
Code: Select allIf position is 35: 35/32 = 1.09   ==>  round(1.09) = 1  ==>  new position = 32*1 = 32
If position is 70: 70/32 = 2.19   ==>  round(2.19) = 2  ==>  new position = 32*2 = 64


i have done up to the line and now it just snaps to 25x25 which im after but its no longer dragable and i dont understand what to click on to input If position is 35: 35/32 = 1.09 ==> round(1.09) = 1 ==> new position = 32*1 = 32
If position is 70: 70/32 = 2.19 ==> round(2.19) = 2 ==> new position = 32*2 = 64
By scott_taylor
#45534 haha feel abit stupid now iv sorted it thanks just a blip in the code lol
By komencanto
#45552 Another formula (found it in Construct Classic example 'Sprite Editor') for the grid 10x10 is:
ObjectPosition=int(MouseX/10)*10, int(MouseY/10)*10
In GD it looks something like this:
No conditions,
Action:
grid_snapping.png
grid_snapping.png (1.74 KiB) Viewed 5723 times

So, if you want 25x25 grid, change 10 to 25.