Discuss Scratch

NightmareMoonChan
Scratcher
100+ posts

Snap to grid help

I am making a PLants vs zombie game and I have a snap to grid and I was wondering how i could focus the snap to grid on a certain bit of area so it can't get dragged out of the certain area
nyankatpro
Scratcher
500+ posts

Snap to grid help

Only let the sprite snap to the grid if you're within the bounds of the area. The exact x and y values depend on how big the grid is in your project. Like this:
if <<<(x position) < [pos x limit]> and <(x position) > [neg x limit]>> and <<(y position) < [pos y limit]> and <(y position) > [neg y limit]>>> then
... //snap to grid code here
end
Edit: the script gets cut off, just repeat the same process with the y position.

Last edited by nyankatpro (April 27, 2021 16:01:39)

Oumuamua
Scratcher
1000+ posts

Snap to grid help

kajtolmation
Scratcher
100+ posts

Snap to grid help

go to x: ((round ((mouse x) / (30))) * (30)) y: ((round ((mouse y) / (30))) * (30))

Another way to do it
thf-217
Scratcher
8 posts

Snap to grid help

kajtolmation wrote:

go to x: ((round ((mouse x) / (30))) * (30)) y: ((round ((mouse y) / (30))) * (30))

Another way to do it
is great!!! thx

Powered by DjangoBB