1
General / Re: Sprite Animation help
« on: December 16, 2013, 02:39:39 am »
Well I was planning on implementing the Animation myself, just something I like to do. So I moved everything into the update function. I also tried adding a clock/timer, I'm not sure this is the best or even a good way of implementing the timer but it was the best I could come up with in an hour and a half. but now it just shows all three frames next to the sprite and each frame next to each other. I'm at a loss here.
void SwordSprite::Update(float elapsedTime)
{
sf::Clock clock;
sf::Time time = sf::seconds(1.0f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
int maxFrame = 2;
SPRITE_HEIGHT = 35;
SPRITE_WIDTH = 44;
if(clock.getElapsedTime() >= time)
{
for(int curFrame = 0; curFrame <= maxFrame; curFrame++)
{
GetSprite().setTextureRect(sf::IntRect(SPRITE_WIDTH * curFrame, 0
, SPRITE_WIDTH, SPRITE_HEIGHT));
GetSprite().setOrigin((GetSprite().getLocalBounds().width / 2) - 9.0f
, (GetSprite().getLocalBounds().height / 2) + 2.0f);
}
}
VisibleGameObject::Update(elapsedTime);
clock.restart();
}
}
{
sf::Clock clock;
sf::Time time = sf::seconds(1.0f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
int maxFrame = 2;
SPRITE_HEIGHT = 35;
SPRITE_WIDTH = 44;
if(clock.getElapsedTime() >= time)
{
for(int curFrame = 0; curFrame <= maxFrame; curFrame++)
{
GetSprite().setTextureRect(sf::IntRect(SPRITE_WIDTH * curFrame, 0
, SPRITE_WIDTH, SPRITE_HEIGHT));
GetSprite().setOrigin((GetSprite().getLocalBounds().width / 2) - 9.0f
, (GetSprite().getLocalBounds().height / 2) + 2.0f);
}
}
VisibleGameObject::Update(elapsedTime);
clock.restart();
}
}