Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Snap to grid?
- MiaPie
-
59 posts
Snap to grid?
How do I make a sprite snap to an irregular grid? Usually I use the following code:
However, in my current project the grid is offset by 4 on the x axis and 8 on the y axis. How can I make the sprite snap to such an offset grid without it hovering around my mouse weirdly?
However, in my current project the grid is offset by 4 on the x axis and 8 on the y axis. How can I make the sprite snap to such an offset grid without it hovering around my mouse weirdly?
- asivi
-
1000+ posts
Snap to grid?
How do I make a sprite snap to an irregular grid? Usually I use the following code:
However, in my current project the grid is offset by 4 on the x axis and 8 on the y axis. How can I make the sprite snap to such an offset grid without it hovering around my mouse weirdly?
This would be doing the job pretty well
If it looks weird check the costume center in the paint editor.
- awesome-llama
-
1000+ posts
Snap to grid?
you can also add numbers to the rounded coordinates to get the sprite in the right position.
- MiaPie
-
59 posts
Snap to grid?
The game is a mining simulator, and I need this crosshairs sprite to snap onto the blocks so it is only touching one block at a time. That's why it has to move in 16 pixel increments. Normally i could just do the code I submitted in the OP, but I want the crosshair to match exactly. If I do addition (adding 4 to the x for example) it looks weird and I can't make it look normal again.
- awesome-llama
-
1000+ posts
Snap to grid?
Can you share and link the project?
Last edited by awesome-llama (June 24, 2017 01:13:01)
- asivi
-
1000+ posts
Snap to grid?
Make two costumes for those blocks, one with the crosshair painted on and the othe without it, so all that you need to do is a costume change.
That if i'm not missunderstanding you otherwise explain you want to achieve more in detail.
That if i'm not missunderstanding you otherwise explain you want to achieve more in detail.
Last edited by asivi (June 24, 2017 10:12:54)
- CatOverload
-
100+ posts
Snap to grid?
You can't figure this out without acutally knowing the pixel dimensions in each block. (Or maybe not, i can't figure it out any other way) You can find the dimensions in the Costume section (Xdim. x Ydim. ) But i'm not sure if you made it with clones, or if you made the whole map by itself. If the latter, you'll have to redesign the whole map, and even maybe the mechanics.
Sorry, please get back to me if you think this might be a solution
\\\
Sorry, please get back to me if you think this might be a solution

- gtoal
-
1000+ posts
Snap to grid?
drag and drop with snap to grid demo: https://scratch.mit.edu/projects/58544578/
- griefercube
-
500+ posts
Snap to grid?
Ah yes just type it in and add a number that’s it! The game is a mining simulator, and I need this crosshairs sprite to snap onto the blocks so it is only touching one block at a time. That's why it has to move in 16 pixel increments. Normally i could just do the code I submitted in the OP, but I want the crosshair to match exactly. If I do addition (adding 4 to the x for example) it looks weird and I can't make it look normal again.
- griefercube
-
500+ posts
Snap to grid?
Like this:
Last edited by griefercube (Sept. 7, 2020 00:07:50)
- deck26
-
1000+ posts
Snap to grid?
Please don't necropost - this is from 2017. Your post doesn't add anything new.Ah yes just type it in and add a number that’s it! The game is a mining simulator, and I need this crosshairs sprite to snap onto the blocks so it is only touching one block at a time. That's why it has to move in 16 pixel increments. Normally i could just do the code I submitted in the OP, but I want the crosshair to match exactly. If I do addition (adding 4 to the x for example) it looks weird and I can't make it look normal again.
- joshuaho
-
1000+ posts
Snap to grid?
Thanks for your help! However, this thread is old - so I doubt they're still looking for answers. I would suggest looking for newer topics (that still need to be answered) and respond to those.Ah yes just type it in and add a number that’s it! The game is a mining simulator, and I need this crosshairs sprite to snap onto the blocks so it is only touching one block at a time. That's why it has to move in 16 pixel increments. Normally i could just do the code I submitted in the OP, but I want the crosshair to match exactly. If I do addition (adding 4 to the x for example) it looks weird and I can't make it look normal again.

- Discussion Forums
- » Help with Scripts
-
» Snap to grid?