Here’s what I have.
I too am working on a tile based game, and wanted smooth walking. To get tile based movement with animated walking between tiles, I made it so that when you press a direction, say left, it sets your xDir value to -1, which represents left. It also sets moveDistance to 16, since my tiles are 16x16. Now, on every pass, it will subtract one from moveDistance, and, depending on the xDir and yDir variables, it will change your x or y coordinate.
Checking if done moving to a new tile
if (moveDistance == 0) {
newDir = 4;
xDir = 0;
yDir = 0;
int tx = 0, ty = 0;
if (listener.turn.down) {
if (listener.up.down) dir = UP;
else if (listener.down.down) dir = DOWN;
else if (listener.left.down) dir = LEFT;
else if (listener.right.down) dir = RIGHT;
} else {
if (listener.up.down) ty = -1;
else if (listener.down.down) ty = 1;
else if (listener.left.down) tx = -1;
else if (listener.right.down) tx = 1;
}
if (Tile.checkEmpty(x / 16 + tx, y / 16 + ty, true)) {
Tile.tilesArray[x / 16][y / 16] = Tile.EMPTY;
Tile.tilesArray[x / 16 + tx][y / 16 + ty] = Tile.PLAYER;
cx = x / 16 + tx;
cy = y / 16 + ty;
if (ty == -1) newDir = UP;
if (ty == 1) newDir = DOWN;
if (tx == -1) newDir = LEFT;
if (tx == 1) newDir = RIGHT;
} else {
if (ty == -1) dir = UP;
else if (ty == 1) dir = DOWN;
else if (tx == -1) dir = LEFT;
else if (tx == 1) dir = RIGHT;
}
if (newDir != 4) {
dir = newDir;
moveDistance = 16;
}
}
Moving in the Y direction
if (yDir != 0) {
y += yDir;
if (y > Game.HEIGHT / 2 - 9 && y < Level.levelHeight - (Game.HEIGHT / 2) - 7) {
super.updateOffs(0, yDir);
if ((y - yoffs) < centerY) {
yoffs--;
} else if ((y - yoffs) > centerY) {
yoffs++;
}
}
} else {
super.updateOffs(0, yDir);
}
Moving in the X direction
if (xDir != 0) {
x += xDir;
if (x > Game.WIDTH / 2 - 9 && x < Level.levelWidth - (Game.WIDTH / 2) - 7) {
super.updateOffs(xDir, 0);
if ((x - xoffs) < centerX) {
xoffs--;
} else if ((x - xoffs) > centerX) {
xoffs++;
}
}
} else {
super.updateOffs(xDir, 0);
}
Hope this helps.
-Nate