fix overlaping animations

This commit is contained in:
serk 2017-01-21 13:32:20 +01:00
parent 1184a03f5f
commit a843c0faca
4 changed files with 12 additions and 7 deletions

View file

@ -2,7 +2,7 @@
Actor::Actor() {} Actor::Actor() {}
Actor::Actor(int num) { Actor::Actor(int num) {
animate = true; animate = PlayerState::attacking;
this->character = new Character(num); this->character = new Character(num);
} }
@ -12,9 +12,12 @@ void Actor::draw(sf::RenderWindow *window) {
bool Actor::update(float deltaTime, sf::RenderWindow *window) { bool Actor::update(float deltaTime, sf::RenderWindow *window) {
character->update(deltaTime); character->update(deltaTime);
if (animate) { if (animate == PlayerState::attacking) {
character->setState(PlayerState::attacking); character->setState(PlayerState::attacking);
animate = false; animate = PlayerState::inMidle;
}
else if (animate == PlayerState::inMidle) {
if (character->isLastFrame()) animate = PlayerState::idle;
} }
return this->updateLogic(deltaTime, window); return this->updateLogic(deltaTime, window);
} }

View file

@ -17,7 +17,7 @@ public:
virtual bool event(sf::Event e) = 0; virtual bool event(sf::Event e) = 0;
protected: protected:
Compas compas; Compas compas;
bool animate; PlayerState::playerState animate;
virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0; virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0;
private: private:
Character *character; Character *character;

View file

@ -41,7 +41,7 @@ namespace GameScene {
} }
namespace PlayerState { namespace PlayerState {
enum playerState{idle, attacking}; enum playerState{idle, attacking, inMidle};
} }
#endif // COMMONS_HPP #endif // COMMONS_HPP

View file

@ -18,8 +18,10 @@ bool Player::event(sf::Event e) {
case (sf::Event::KeyPressed): case (sf::Event::KeyPressed):
if(e.key.code == sf::Keyboard::C) compas.start(); if(e.key.code == sf::Keyboard::C) compas.start();
if(e.key.code == sf::Keyboard::Space) { if(e.key.code == sf::Keyboard::Space) {
if (compas.isPressed() && animate == PlayerState::idle) {
compas.add(); compas.add();
if (compas.isPressed() && !animate) animate = true; animate = PlayerState::attacking;
}
} }
break; break;
case (sf::Event::KeyReleased): case (sf::Event::KeyReleased):