The concept is straightforward: I have a tile based game and moving with the arrow keys moves you in 1 of four directions. I also have animations sequenced with these movements. Seems very simple, right? Well the problem that I'm running into is that I want the animations between tiles to be very smooth when continuously walking, for example holding down the arrow key for several tiles. Currently, at best I can get a short pause between tiles.
I know the problem must be that I'm simply not a very experienced game developer so I'm probably going about it all wrong. I would really appreciate it if someone could give me some pseudo code and explain the general process that this should be done.
Here's what I'm basically attempting right now (pseudo code, will write code for only 1 key, to simplify it)
// called every frame
function () {
if(left_key_down)
++left_key_down_frames;
else
left_key_down_frames = 0;
if(left_key_down_frames > 6)
player.walk()
}
player.walk function() {
if(!player.canWalk)
return; // player can't walk
player.move(movement_finished_callback()); // move player to correct place
player.animate(); // animate the frames accordingly..
}
movement_finished_callback function() {
player.canWalk = true;
}