Sign in to follow this  

Sliding a Tile Smoothly

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I'm writing a tile based game, and as it stands, my rendering code takes a tile position from a 2D array, converts it to screen coordinates, and draws the appropriate tile image. The game code is completely abstracted from the rendering code. I want to swap tiles in the game. Right now, the swap is instantaneous, and quite jarring. I'd like to have a smooth movement-based animation that swaps the two tiles over, say, half a second. I've got some loose ideas on how to accomplish this, like introducing screen coordinates to my tile objects, or creating an animation class hierarchy, but if any of you had some advice to give before I proceed it'd be much appreciated. Thanks, - carb

Share this post


Link to post
Share on other sites
What I do, is create two instances of the Tile class. The one that's the core data and then an onscreen instance, that has no world-associated data, just onscreen coordinates and an Image or Animation.

If you want to "swap", by this I assume you mean replace one tile with another in one location, you could create two onscreen instances and have them "swap". This would keep your base Tile class as a world-relative object while actually moving the scratch object that gets deleted when it's momentary scope expires.

Share this post


Link to post
Share on other sites
I was glancing through some articles here on Gamedev, and one suggestion I came across was to store, in addition to the tile coordinates, pixel offsets in x and y from the tile position. These offsets can be set and updated from the "game" subsystem when a tile swap or other movement-based animation occurs.

Afterwards, the rendering subsystem can simply apply that offset as it iterates through the tiles and draws them.

It seems like such an easy concept in retrospect ;)

- carb

Share this post


Link to post
Share on other sites
Quote:
Original post by carb
I was glancing through some articles here on Gamedev, and one suggestion I came across was to store, in addition to the tile coordinates, pixel offsets in x and y from the tile position. These offsets can be set and updated from the "game" subsystem when a tile swap or other movement-based animation occurs.

Afterwards, the rendering subsystem can simply apply that offset as it iterates through the tiles and draws them.

It seems like such an easy concept in retrospect ;)

- carb


That was exactly what I was going to suggest you do. [smile] If you are using a time-based movement loop I think it would work really well. First draw a frame, then update your game status according to how much time passed since you last updated the game (ie, if the frame draw took 10ms, make your tile offset 10 pixels, if it took 20ms, make it 20 pixels, etc.). This will provide very smooth tile traversal across the map, and even if the user's system is low-end, it will still look "as smooth as possible" on that system.

It's simple, efficient, and not too hard to implement. [grin]

Share this post


Link to post
Share on other sites

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this