I was wondering how I could make a 15*15 sprite snap to this grid:
Every square is 16*16.
Offline
set x to ((round ((x position) / (16))) * (16)) set y to ((round ((y position) / (16))) * (16))You may need to also add a +8 before the rounding and a -8 after, it depends.
Offline
zubblewu wrote:
set x to ((round ((x position) / (16))) * (16)) set y to ((round ((y position) / (16))) * (16))You may need to also add a +8 before the rounding and a -8 after, it depends.
I tried that before, but it didn't work. I'll try it with the +8/-8 though.
Offline
Offline
ImagineIt wrote:
Not working still...
And how is it not working?
Last edited by ErnieParke (2012-10-28 15:13:33)
Offline
ErnieParke wrote:
ImagineIt wrote:
Not working still...
And how is it not working?
It snaps to the wrong places. ex: In the middle of two.
Offline
ImagineIt wrote:
zubblewu wrote:
set x to ((round ((x position) / (16))) * (16)) set y to ((round ((y position) / (16))) * (16))You may need to also add a +8 before the rounding and a -8 after, it depends.I tried that before, but it didn't work. I'll try it with the +8/-8 though.
To this, but try changing the + whatevers.
Offline
Can you upload what you have so far?
I'll fix it. I know what's happening, I've had the same problem.
Offline
ImagineIt wrote:
ErnieParke wrote:
ImagineIt wrote:
Not working still...
And how is it not working?
It snaps to the wrong places. ex: In the middle of two.
So could you do something for me? If the sprite was at (0,0) where would it go? How about (8,8) and (16,16)?
Offline
ErnieParke wrote:
ImagineIt wrote:
ErnieParke wrote:
And how is it not working?
It snaps to the wrong places. ex: In the middle of two.
So could you do something for me? If the sprite was at (0,0) where would it go? How about (8,8) and (16,16)?
0,0(Starting at the bottom left) = -171, -172; 8,8 = -52, -51; 16,16 = 69, 68. Thanks for your help guys. I'll try to upload it.
Edit: Wait, I just had an Idea. I'll upload after I try it.
Edit: OK, Now the x and y coordinates will always be equal when snapped to the grid, but they still don't get snapped to it.
Last edited by ImagineIt (2012-10-28 15:46:52)
Offline
ImagineIt wrote:
ErnieParke wrote:
ImagineIt wrote:
It snaps to the wrong places. ex: In the middle of two.So could you do something for me? If the sprite was at (0,0) where would it go? How about (8,8) and (16,16)?
0,0(Starting at the bottom left) = -171, -172; 8,8 = -52, -51; 16,16 = 69, 68. Thanks for your help guys. I'll try to upload it.
Edit: Wait, I just had an Idea. I'll upload after I try it.
Edit: OK, Now the x and y coordinates will always be equal when snapped to the grid, but they still don't get snapped to it.
When I said (0,0), I meant in Scratch, not your grid. Also, do you want the square snapped to the middle of squares or at the points where 4 squares touch?
Offline
ErnieParke wrote:
ImagineIt wrote:
ErnieParke wrote:
So could you do something for me? If the sprite was at (0,0) where would it go? How about (8,8) and (16,16)?0,0(Starting at the bottom left) = -171, -172; 8,8 = -52, -51; 16,16 = 69, 68. Thanks for your help guys. I'll try to upload it.
Edit: Wait, I just had an Idea. I'll upload after I try it.
Edit: OK, Now the x and y coordinates will always be equal when snapped to the grid, but they still don't get snapped to it.When I said (0,0), I meant in Scratch, not your grid. Also, do you want the square snapped to the middle of squares or at the points where 4 squares touch?
In the middle of squares. I'm uploading it now.
Offline
Offline
Snap To Grid Wiki Article.
What you probably want to do is "shift" your sprite to match your grid.
set x to (((16)*(round(((x position)-(shiftx))/(16))))+(shiftx)) set y to (((16)*(round(((y position)-(shifty))/(16))))+(shifty))
Offline
Hm... That works at the bottom left, but then once it gets further away, it will not snap in still. How can I automatically set the shift?
Offline
Offline
ImagineIt wrote:
Hm... That works at the bottom left, but then once it gets further away, it will not snap in still. How can I automatically set the shift?
Your problem may be that, though every square is 16x16, the lines between the squares have a thickness too. If the lines are 1 pixel thick, use 17 instead of 16.
Offline
MoreGamesNow wrote:
ImagineIt wrote:
Hm... That works at the bottom left, but then once it gets further away, it will not snap in still. How can I automatically set the shift?
Your problem may be that, though every square is 16x16, the lines between the squares have a thickness too. If the lines are 1 pixel thick, use 17 instead of 16.
No, the inside of the square is 15 pixels, the outline is 1 pixel. I just figured out what the problem is though. The pixels are shared instead of being separate. That's what causes it to go out of place. I just don't WANT them to not share pixels. So, we just need to find a way to change the snap. Oh! I think I found out how! Let me test it now!
Offline
Offline
Wait... Not fully... When I move the mouse one pixel, it can have weird effects.
Last edited by ImagineIt (2012-10-28 21:29:10)
Offline
I just did a pixel count and it should be 15 (14 on the inside and border of 1 pixel). Can you update the project in the link above with the latest version?
Offline