http://scratch.mit.edu/projects/1675/2044404
open it click play press a and try clicking in the upper big of the second column, notice that is doesn't snap to the right square
there is a sprite called snap
i need this urgent please please help!
Offline
I would do away with the many if-else statements and try a formula.
I noticed that your squares are 28x28.
set x to: (Round((mouse X - number)/28))*28+number
A similar code for the y-coordinate. The "number" is a number that you'll have to find to make sure "snap" is properly aligned. Just toy around with it until it fits.
Offline
MoreGamesNow wrote:
I would do away with the many if-else statements and try a formula.
I noticed that your squares are 28x28.Code:
set x to: (Round((mouse X - number)/28))*28+numberA similar code for the y-coordinate. The "number" is a number that you'll have to find to make sure "snap" is properly aligned. Just toy around with it until it fits.
could you explain to me how this works?
Offline
I can.
Imagine this. You take several numbers. 10, 23, 12.
Divide it by 10. You get 1, 2.3, 1.2.
Round it. (Scratch can only round to the nearest integer) You get 1, 2, 1.
Multiply it by 10 (What you started out dividing by). You get 10, 20, 10.
You just rounded three numbers to the nearest 10.
In this case, you have sprites that are 28x28, so you want to round to 28 pixels.
Because you have a grid, you might want to: A) align the sprite to the grid or B) align the grid to the sprite.
To align the grid, just move the grid. To align the sprite, you have to change some stuff.
Because you are rounding to 28 pixels, it'll snap to 0, 28, 56, etc. But to make it snap to 2, 30, or something, you need to add 2.
Find the correct number to snap to, and add that number. It should work. It's late and I'll help you more tomorrow.
Offline
kayybee wrote:
I can.
Imagine this. You take several numbers. 10, 23, 12.
Divide it by 10. You get 1, 2.3, 1.2.
Round it. (Scratch can only round to the nearest integer) You get 1, 2, 1.
Multiply it by 10 (What you started out dividing by). You get 10, 20, 10.
You just rounded three numbers to the nearest 10.
In this case, you have sprites that are 28x28, so you want to round to 28 pixels.
Because you have a grid, you might want to: A) align the sprite to the grid or B) align the grid to the sprite.
To align the grid, just move the grid. To align the sprite, you have to change some stuff.
Because you are rounding to 28 pixels, it'll snap to 0, 28, 56, etc. But to make it snap to 2, 30, or something, you need to add 2.
Find the correct number to snap to, and add that number. It should work. It's late and I'll help you more tomorrow.
omg wow i get it now I'm so stupid! lol!
Offline
kayybee wrote:
I can.
Imagine this. You take several numbers. 10, 23, 12.
Divide it by 10. You get 1, 2.3, 1.2.
Round it. (Scratch can only round to the nearest integer) You get 1, 2, 1.
Multiply it by 10 (What you started out dividing by). You get 10, 20, 10.
You just rounded three numbers to the nearest 10.
In this case, you have sprites that are 28x28, so you want to round to 28 pixels.
Because you have a grid, you might want to: A) align the sprite to the grid or B) align the grid to the sprite.
To align the grid, just move the grid. To align the sprite, you have to change some stuff.
Because you are rounding to 28 pixels, it'll snap to 0, 28, 56, etc. But to make it snap to 2, 30, or something, you need to add 2.
Find the correct number to snap to, and add that number. It should work. It's late and I'll help you more tomorrow.
whats the minus there for though?
Offline
That just shifts the imaginary/invisible grid over by a number. The distance is still 28, just at what point the sprite snaps to a different square changes.
Offline
kayybee wrote:
I can.
Imagine this. You take several numbers. 10, 23, 12.
Divide it by 10. You get 1, 2.3, 1.2.
Round it. (Scratch can only round to the nearest integer) You get 1, 2, 1.
Multiply it by 10 (What you started out dividing by). You get 10, 20, 10.
You just rounded three numbers to the nearest 10.
In this case, you have sprites that are 28x28, so you want to round to 28 pixels.
Because you have a grid, you might want to: A) align the sprite to the grid or B) align the grid to the sprite.
To align the grid, just move the grid. To align the sprite, you have to change some stuff.
Because you are rounding to 28 pixels, it'll snap to 0, 28, 56, etc. But to make it snap to 2, 30, or something, you need to add 2.
Find the correct number to snap to, and add that number. It should work. It's late and I'll help you more tomorrow.
I love math, but I always like to know why. So thanks.
Last edited by PullJosh (2011-11-26 18:20:27)
Offline
MoreGamesNow wrote:
I would do away with the many if-else statements and try a formula.
I noticed that your squares are 28x28.Code:
set x to: (Round((mouse X - number)/28))*28+numberA similar code for the y-coordinate. The "number" is a number that you'll have to find to make sure "snap" is properly aligned. Just toy around with it until it fits.
Thanks loads! This really helped in my minecraft game!
Offline
You didn't need to necropost. Just tell him/her that you appreciate their help through a comment.
Offline
Please link. Look at the BBC code for help.
Offline