This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-05 22:13:03

1675
Scratcher
Registered: 2009-06-17
Posts: 21

urgent grid snap problem

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

 

#2 2011-10-05 22:55:35

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: urgent grid snap problem

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+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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2011-10-06 01:13:47

1675
Scratcher
Registered: 2009-06-17
Posts: 21

Re: urgent grid snap problem

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+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.

could you explain to me how this works?

Offline

 

#4 2011-10-06 01:34:20

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: urgent grid snap problem

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

 

#5 2011-10-06 02:01:25

1675
Scratcher
Registered: 2009-06-17
Posts: 21

Re: urgent grid snap problem

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

 

#6 2011-10-07 03:15:48

1675
Scratcher
Registered: 2009-06-17
Posts: 21

Re: urgent grid snap problem

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

 

#7 2011-10-07 07:39:17

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: urgent grid snap problem

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2011-10-07 19:38:14

1675
Scratcher
Registered: 2009-06-17
Posts: 21

Re: urgent grid snap problem

k thx

Offline

 

#9 2011-11-05 12:50:39

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: urgent grid snap problem

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.  big_smile

Last edited by PullJosh (2011-11-26 18:20:27)


http://www.blocks.scratchr.org/API.php?action=text&string=I'm_on_vacation!&xpos=155&ypos=90&font_size=30&bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#10 2012-03-17 12:26:27

bannanaman
Scratcher
Registered: 2011-01-15
Posts: 25

Re: urgent grid snap problem

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+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.

Thanks loads! This really helped in my minecraft game!


*Want a Minecraft Mod? -Yes *Cant find one of you're liking?-Yes *Well you've come to the right place!  wink -Yay! *Message me on one of my projects(preferably my Minecraft mod project for commenting) where you can apply for me to make one for you!
Hope to see you soon!  smile  *** You could visit my (Under construction) website at http://minecraftmodmakers4u.webs.com/ ***

Offline

 

#11 2012-03-17 12:35:59

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: urgent grid snap problem

You didn't need to necropost. Just tell him/her that you appreciate their help through a comment.


Why

Offline

 

#12 2012-03-17 12:47:51

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: urgent grid snap problem

Please link. Look at the BBC code for help.

Offline

 

Board footer