Ok, I am making a Zelda game similar to a Link To The Past. I am trying to make my character animation's image default to 0 whenever i release one of the direction buttons on my keyboard. This works about 85% of the time. Is there something wrong with this code?
void Character::Movement()
{
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))
{
currentView = UP;
spriteFrame++;
if(spriteFrame >= 9)
spriteFrame = 0;
for(int i=0; i < spriteFrame; ++i)
LinkSprite.SetImage(linkup[i], false);
LinkSprite.Move(0.f, -speed);
}
else if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))
{
currentView = DOWN;
spriteFrame++;
if(spriteFrame >= 9)
spriteFrame = 0;
for(int i=0; i < spriteFrame; ++i)
LinkSprite.SetImage(linkdown[i], false);
LinkSprite.Move(0.f, speed);
}
else if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
{
currentView = RIGHT;
spriteFrame++;
if(spriteFrame >= 9)
spriteFrame = 0;
for(int i=0; i < spriteFrame; ++i)
LinkSprite.SetImage(linkright[i], true);
LinkSprite.Move(speed, 0.f);
}
else if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
{
currentView = LEFT;
spriteFrame++;
if(spriteFrame >= 9)
spriteFrame = 0;
for(int i=0; i < spriteFrame; ++i)
LinkSprite.SetImage(linkleft[i], true);
LinkSprite.Move(-speed, 0.f);
}
}
void Character::KeyRelease()
{
if(sf::Event::KeyReleased && sf::Keyboard::Right && currentView == RIGHT)
LinkSprite.SetImage(linkright[0]);
if(sf::Event::KeyReleased && sf::Keyboard::Left && currentView == LEFT)
LinkSprite.SetImage(linkleft[0]);
if(sf::Event::KeyReleased && sf::Keyboard::Up && currentView == UP)
LinkSprite.SetImage(linkup[0]);
if(sf::Event::KeyReleased && sf::Keyboard::Down && currentView == DOWN)
LinkSprite.SetImage(linkdown[0]);
}