Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm talking about where if you press a directional key once you walk over to the adjacent tile and can't do any other actions during the walk. I can get my character to move one tile width, but my trouble is animating the walk and having the character actually walk to the next tile, rather than teleport. The research I've done has pointed me in the direction of interpolation, but I don't really understand how to get it working.

share|improve this question
up vote 2 down vote accepted

The easiest way is to use linear interpolation (AKA lerp) over time.

Let's say you want you character to move from posA to posB. You calculate it's current position every frame from those two positions, the current time (incremented by a delta time every frame), and the wanted movement duration, as follows:

float t = currentTime / moveDuration
vector currentPos = posA  + (posB - posA) * t

This movement might feel a bit mechanical but that's a good first step, if you want to go further, look into easing functions:

share|improve this answer
Make sure to do check for 0 < t < 1 in order to disable player input during this time. The last thing you want is seeing something unexpected if the player tries other actions during the walk, such as buffering a lot of walk actions that won't stop for a long time. – ChrisC Aug 17 '12 at 2:09
Thanks! I'll look into this and see if I can get it working. – user1500452 Aug 17 '12 at 14:29
I've gotten the interpolation working, and I'm getting a the pixel values for everything in between 128 and 144, which is great. Thanks for the help. My problem now is getting the position of the image to update every time the position of the image is changed. I'm using Slick link and I'm not sure where to go from here. I'll look around the slick forums for this, but if anyone knows anything and can post it here it would be appreciated. – user1500452 Aug 17 '12 at 15:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.