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

#1 2012-08-19 01:10:47

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Tile based movement

How do you make a sprite move based on tile movement e.g like pokèmon


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#2 2012-08-19 05:15:31

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Re: Tile based movement

Bump


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#3 2012-08-19 09:21:37

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

Re: Tile based movement

Just only allow movement along set intervals (like below).  Alternatively you could "snap to a grid" (there's a wiki article on that), but I'm pretty sure that's not the effect you're looking for.

when gf clicked
forever
if<key [right arrow v] pressed?>
repeat (10)
change x by (1)
end
end
if<key [left arrow v] pressed?>
repeat (10)
change x by (-1)
end
end
if<key [up arrow v] pressed?>
repeat (10)
change y by (1)
end
end
if<key [down arrow v] pressed?>
repeat (10)
change y by (-1)
end
end


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

Offline

 

#4 2012-08-19 16:43:02

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Re: Tile based movement

It could work ,but what if you bump into a building?


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#5 2012-08-19 16:56:13

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

Re: Tile based movement

Assuming it is top-down, the below script is one way.  If it is more 3-D looking, I'd have a 2-D list with whether a block can be moved through and check that (if that's the case, I can try to give you a script for that).

when gf clicked
forever
if<key [right arrow v] pressed?>
change x by (10)
if<not<touching [wall v]?>>
change x by (-10)
repeat (10)
change x by (1)
end
else
change x by (-10)
end
end
etc.


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

Offline

 

#6 2012-08-21 00:59:27

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Re: Tile based movement

I actually wanted something more accurate


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#7 2012-08-21 08:56:43

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

Re: Tile based movement

What do you mean "accurate".  A smaller grid?


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

Offline

 

#8 2012-08-21 09:15:07

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Re: Tile based movement

Like you move from block a1 to b1


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#9 2012-08-21 11:11:41

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

Re: Tile based movement

I'm not sure exactly what you want.  Do you want a script that returns a sprite's x and y position on the grid?  A script that uses a 2D array for wall collision?


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

Offline

 

#10 2012-08-21 16:34:28

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Re: Tile based movement

Yes


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#11 2012-08-21 17:40:29

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

Re: Tile based movement

A script that uses a 2D array for wall collision?


The script for a sprite's x and y position on a grid looks something like this:

set [x v] to ((round(((x position)-[horizontal shift])/(tile_size)))+[some number])
set [y v] to ((round(((y position)-[vertical shift])/(tile_size)))+[some other number])
horizontal and vertical shifts, as well as "some number" are simply correction values that depend on a ton of things (like where the center of the sprite is, how the grid is shifted, etc.).  The simplest way to find them is trial and error.  It's difficult to explain how to find them though, anyone want to give it a shot?


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

Offline

 

#12 2012-08-23 01:02:04

Jodymoses
Scratcher
Registered: 2012-05-03
Posts: 100+

Re: Tile based movement

Is it x-hs/tile size +some number in that order


http://i46.tinypic.com/2hxwx9s.png
I Have Huge Ideas, But Only If You Listen And Talk To Me...

Offline

 

#13 2012-08-23 22:05:34

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

Re: Tile based movement

Code:

((x-hs)/(tile_size)) + some number

Thinking back on it, "horizontal shift" and "some number" are probably the same number.  I'm away from home visiting relatives right now so I can't confirm it  hmm


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

Offline

 

Board footer