Archived

This topic is now archived and is closed to further replies.

sj

Moving in tile-based games.

Recommended Posts

How would I make a game character move from a tile to another, not just "jump" there but so that it would look like it walked there (or slided)? It would be helpful if you could give me some hints or if you could point me where to find some information about it. Thanks for replys.

Share this post


Link to post
Share on other sites
There are 2 ways which come to mind.

What I use in my game (an rts), is to store a units location as an xy coordinate using pixel measurements, which means that moving the unit smoothly is just a matter of changing that coordinate. Then, to quickly find out which unit is on which square, each tile has a handle to the unit which is on it, or moving onto it. As you move the unit, you need to update the handle (you can use a pointer if you want, but for my purposes, a handle has a few extra benefits), dereferencing the old square and referencing the new.

Alternatively, some people store an xy offset with the unit, and when it comes to drawing the unit, the xy offset is added to the usual location. Fairly similar, it only really gives you a major advantage if you have a slowdown occuring when trying to work out which tile the unit is on, apart from that, it would probably just make it harder for you to keep track of the unit (having to adjust 4 coordinates instead of 2). Again, a handle/pointer would be put on each tile so you can quickly find out which unit is on a tile. Even if you don''t see a need for this, do it, you will suddenly get to a point where you do, and you don''t want to have to cycle through each unit to find out where they are. The overhead is minimal.

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
I like storing unit coordinates as floats. 0.0,0.0 would be the top corner of the first isometric tile, 0.5,0.5 would be exactly in the middle of it, 1.0,1.0 would be the bottom corner, or the top corner of the tile at (1,1)
The advantage of this is that you have everything in map coordinates and can calculate distances or so very easily.

Greetings,
Tweedledeeeeeee

Share this post


Link to post
Share on other sites
The Scrolling Game Development Kit represents all sprite positions by representing them as the distance, in pixels, from the top left corner of the map/layer. They are stored as single precision floating point numbers in order to easily facilitate velocities less than 1 pixel per frame (and of course any velocity that is not an integer). The source code is also freely available at the site if you want to see how it was done.

"All you need to do to learn circular logic is learn circular logic"

Share this post


Link to post
Share on other sites