I added the var "direction" to keep track of which key was pressed last and used that var in my logical arguments, but it still isn't working.
Quote: "
stop the animation when the player stops
"
the only way i know how to check if the player stops is by checking if a key is not pressed, but i need to keep track of the last key that was pressed so that i know which frame to set it to.
int player::move()
{
char direction;
// if W Key
if(dbKeyState(17) == 1)
{
dbPlaySprite(1, 5, 8, 160);
direction = 'W';
}
if(direction == 'W' && dbKeyState(17) != 1)
{
dbSetSpriteFrame(1, 6);
}
// if S Key
if(dbKeyState(31) == 1)
{
dbPlaySprite(1, 1, 4, 160);
direction = 'S';
}
if(direction == 'S' && dbKeyState(31) != 1)
{
dbSetSpriteFrame(1, 2);
}
// if A Key
if(dbKeyState(30) == 1)
{
dbPlaySprite(1, 11, 12, 160);
direction = 'A';
}
if(direction == 'A' && dbKeyState(30) != 1)
{
dbSetSpriteFrame(1, 11);
}
// if D Key
if(dbKeyState(32) == 1)
{
dbPlaySprite(1, 9, 10, 160);
direction = 'D';
}
if(direction == 'D' && dbKeyState(32) != 1)
{
dbSetSpriteFrame(1, 9);
}
return 0;
}