sprite movement?

Started by
0 comments, last by Funkapotamus 18 years, 3 months ago
i am doing an RPG sprite game in opengl , c++. I need to move the character using the keys. i got a input function (processSpecialKeys) like this: if pressed left then { for (i = 1 to 10) { // 1 to 10 (0.1 * 10 = 1, moved one tile) hero.x = hero.x + 0.1; move to next frame; render; sleep(25ms); //wait 25ms, // gives time to show animation } } the prob is that when i press a movement such as (left to right) there is a little pause (i think becuase of sleep() ), that makes the movement unrealstic. i need the character movement AND animation to be smooth and fast. Is there a better way to move the character? is there a way to do this whole thing in the display function() that is refreshed like every milliseconds?
Advertisement
Rendering should be done seperate of the game's logic. For example:
void gameLoop() {   update();   render();   sleep(1000ms / 60); // 60fps}void update() {   // Do Input and move things}void render() {   // Render everything}
For the character's movement delay, I'd set a cap on how many times the game registers movement input. For example, if the player hits left, don't register another movement command until X ammount of time has passed. Allow the button to be pressed, but don't process any logic. Then, sync your sprite's animation to X as well. That way you'll ensure the sprite gets done with its walking animation by the time the next input is registered.

This topic is closed to new replies.

Advertisement