fix overlaping animations
This commit is contained in:
parent
1184a03f5f
commit
a843c0faca
4 changed files with 12 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
Actor::Actor() {}
|
||||
|
||||
Actor::Actor(int num) {
|
||||
animate = true;
|
||||
animate = PlayerState::attacking;
|
||||
this->character = new Character(num);
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,12 @@ void Actor::draw(sf::RenderWindow *window) {
|
|||
|
||||
bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
||||
character->update(deltaTime);
|
||||
if (animate) {
|
||||
if (animate == 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);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
virtual bool event(sf::Event e) = 0;
|
||||
protected:
|
||||
Compas compas;
|
||||
bool animate;
|
||||
PlayerState::playerState animate;
|
||||
virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0;
|
||||
private:
|
||||
Character *character;
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace GameScene {
|
|||
}
|
||||
|
||||
namespace PlayerState {
|
||||
enum playerState{idle, attacking};
|
||||
enum playerState{idle, attacking, inMidle};
|
||||
}
|
||||
|
||||
#endif // COMMONS_HPP
|
||||
|
|
|
@ -18,8 +18,10 @@ bool Player::event(sf::Event e) {
|
|||
case (sf::Event::KeyPressed):
|
||||
if(e.key.code == sf::Keyboard::C) compas.start();
|
||||
if(e.key.code == sf::Keyboard::Space) {
|
||||
if (compas.isPressed() && animate == PlayerState::idle) {
|
||||
compas.add();
|
||||
if (compas.isPressed() && !animate) animate = true;
|
||||
animate = PlayerState::attacking;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (sf::Event::KeyReleased):
|
||||
|
|
Reference in a new issue