Created
March 14, 2013 21:25
-
-
Save Groogy/5165427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Animation::update(sf::Time dt) | |
{ | |
sf::Time timePerFrame = mLength / mNumFrames; | |
mElapsedTime += dt; | |
sf::Vector2i textureBounds = mSprite.getTexture().getSize(); | |
sf::FloatRect textureRect = mSprite.getTextureRect(); | |
if (mCurrentFrame == 0) | |
textureRect = sf::FloatRect(0, 0, mFrameSize.x, mFrameSize.y); | |
while (mElapsedTime >= timePerFrame) | |
{ | |
textureRect.left += textureRect.width; | |
if (textureRect.left + textureRect.width > textureBounds.x) | |
{ | |
textureRect.left = 0; | |
textureRect.top += textureRect.height; | |
} | |
mCurrentFrame = mCurrentFrame + 1 % mNumFrames; | |
mElapsedtime -= timePerFrame; | |
if (mCurrentFrame == 0) | |
textureRect = sf::FloatRect(0, 0, mFrameSize.x, mFrameSize.y); | |
} | |
mSprite.setTextureRect(textureRect); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment