I want to code something similar to how the animate function works with jQuery:
var duration = 500, moveY = "50px", moveX = "70px";
$("#someBox").animate({top: moveY, left: moveX}, duration);
Here I have a box or container which would move right 70px and down 50px, and that animation would take 500 milliseconds. Now to make this relevant to my game, I'm attempting to make Pokémon style, grid-locked movement:
- Press right
--- Player loses control
--- Character runs through one animation cycle
--- Moves right one tile (eg. 16px)
--- Happens over 0.5 seconds
--- Character stops, player gains control
Right now I can make it so that the character moves in a direction for X amount of time, but it doesn't explicitly move a set amount of pixels per say.. I have a float for moveSpeed and it's just playerPos.x += moveSpeed for the amount of time. I also tried doing playerPos.x += GRID_SIZE, which guarantees that he moves the exact amount of space, but it just teleports and doesn't animate in a transitional movement. It's important that the player sticks strictly to the grid and is never off-centre.
In short, I'd like to make this function:
player.move(direction, distance, duration);
I'm also having trouble with limiting my game loop / making things happen at regular intervals, so this is likely making my problem much harder. Anyway I hope this is clear enough. If not, I'd be happy to try and explain further. Thanks in advance.








