Hi,
So basically I'm making a small platformer game, and I have the textures etc setup for the sprite animation. What I want to know is, is there a better way of doing this? The code I am currently using is:
case RIGHT:
if (globals.ggs == IN_GAME) {
sf::Clock animationClock;
sf::Time clockTimeTemp;
playerSprite.setPosition(playerSprite.getPosition().x + 10, playerSprite.getPosition().y);
while (true) {
clockTimeTemp = animationClock.getElapsedTime();
if (clockTimeTemp.asMilliseconds() >= 7.f) {
break;
}
}
animationClock.restart();
playerSprite.setTexture(p1);
initGame();
while (true) {
clockTimeTemp = animationClock.getElapsedTime();
if (clockTimeTemp.asMilliseconds() >= 7.f) {
break;
}
}
animationClock.restart();
playerSprite.setTexture(p2);
initGame();
while (true) {
clockTimeTemp = animationClock.getElapsedTime();
if (clockTimeTemp.asMilliseconds() >= 7.f) {
break;
}
}
animationClock.restart();
playerSprite.setTexture(p3);
initGame();
while (true) {
clockTimeTemp = animationClock.getElapsedTime();
if (clockTimeTemp.asMilliseconds() >= 10.f) {
break;
}
}
animationClock.restart();
initGame();
}
break;
Even though this works, other mechanics such as jumping haven't been implemented yet, and because of the while(true)'s, I'm worried this will cause things such as delays.
Any better ways?
Thanks,
Jay