# Snap To A Grid Sorta Thing

So If I Wanted To Attempt To Make Plants Vs Zombies On Flowlab, How Would I Make It So Whenever I Spawn A Plant It Snaps To A Grid? Is That Even Possible??

You could use Grid based placement as in this example from the help section:

Otherwise there are more options using expressions, but those details depend on your specific situation. Grid size, allowed movements etc.

You started something and have a link?

I Do Have A Game But All It Is, Is Background Stuff : /

Definitly possible.
As said, for the initial placement you can use the grid option.
For the movement (left/right) you extract the own X position and add or substract 32 for the next placement.
Iâ€™m on the phone, canâ€™t at the moment but might be worth to dig through existing games.
Otherwise, give it a go and ask away

If you use an expression, you can try
(Math.round(A/32))*32

A is where the cursor is.
The output is the position of the block.
Do this with the mouse x and mouse y.

Edit:
32 is the grid size in the editor

1 Like

Here is a simple example using @JR01â€™s suggestion above: https://flowlab.io/game/play/1513028

4 Likes

this expression worked best for me Math.round(A / 8) / 4 my favorite thing about it is that it snaps to the flowlab grid not a different one

Well true @GGSTUDIOS, thatâ€™s if you use the â€śgridâ€ť option in the position behavior.
Only problem is that the position behavior (set to grid) is the only behavior that can use those numbers.
(and Iâ€™m lazy and use the pixel measurements for all behaviors lol)

So hereâ€™s a new expression that gives the correct pixel placements that matches Flowlabâ€™s grid placement:
(Math.round((A-16)/B))*B+16

A = Mouse X or Mouse Y
B = The Grid Size you want (8, 16, 32, 64, etc.)

1 Like

Thanks For All The Support!
Iâ€™ll Try And See What I Can Do c: