Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Animation Stops When 2 Keys Pressed  (Read 1241 times)

0 Members and 1 Guest are viewing this topic.

herooftime24

  • Newbie
  • *
  • Posts: 1
    • View Profile
Animation Stops When 2 Keys Pressed
« on: July 03, 2011, 03:01:03 pm »
Here is my delimma I have a player object that animates fine when only one the movement keys is pressed (I use Left, Up, Right, Down) but when 2 of them are pressed together the player moves but stops animating
this is the code

Code: [Select]

#define keyLeft sf::Key::Left
#define keyRight sf::Key::Right
#define keyUp sf::Key::Up
#define keyDown sf::Key::Down

enum direction {Left, Up, Right, Down};

noMovement = true; //bool

float ElapsedTime = App.GetFrameTime();

if (App.GetInput().IsKeyDown(keyLeft))
{
if (Player.getDirection() != Left)
{
Player.getSprite().Play(6,9);
Player.setDirection(Left);
}
Player.Move(-100*ElapsedTime,0);
noMovement = false;
}

if (App.GetInput().IsKeyDown(keyUp))
{
if (Player.getDirection() != Up)
{
Player.getSprite().Play(3,6);
Player.setDirection(Up);
}
Player.Move(0,-100*ElapsedTime);
noMovement = false;
}

if (App.GetInput().IsKeyDown(keyRight))
{
if (Player.getDirection() != Right)
{
Player.getSprite().Play(9,12);
Player.setDirection(Right);
}
Player.Move(100*ElapsedTime,0);
noMovement = false;
}

if (App.GetInput().IsKeyDown(keyDown))
{
if (Player.getDirection() != Down)
{
Player.getSprite().Play(0,3);
Player.setDirection(Down);
}
Player.Move(0,100*ElapsedTime);
noMovement = false;
}

if(noMovement)
{
Player.getSprite().Stop();
}



So hopefully someone can help me
If more code is needed ill post it all

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Animation Stops When 2 Keys Pressed
« Reply #1 on: July 03, 2011, 03:08:19 pm »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: