How do you set the movement speed of a sprite?
- by rphello101
I'm using Slick 2D/Java to play around with graphics. Getting an image to move is easy:
Input input = gc.getInput();
if(input.isKeyDown(sprite.up)){
sprite.y--;
}else if (input.isKeyDown(sprite.down)){
sprite.y++;
}else if (input.isKeyDown(sprite.left)){
sprite.x--;
}else if (input.isKeyDown(sprite.right)){
sprite.x++;
}
However, this is called on every update, so if you hold up, the sprite moves to the edge of the screen in a few hundred milliseconds. Since coordinates are integers, I can't add less than 1 to slow the sprite down. I'm assuming I must have to implement a timer of some sort or something. Any advice?