Jump to content
  • Advertisement
Sign in to follow this  
tomba

OpenGL sprite movement?

This topic is 4606 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!