Ok, so this is my first time trying to animate a sprite and it worked at first. As you can see, here is my code, perfectly working to move and animate my character to the right.
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetImageColorKey(61, 70, 61);
dbCreateAnimatedSprite(1, "sprite.png", 3, 2, 1);
dbSprite(1,150,150, 1);
// our main loop
while ( LoopGDK ( ) )
{
if(dbRightKey() == 1)
{
dbRotateSprite(1,90);
dbPlaySprite(1,1,3,130);
dbMoveSprite(1,1);
dbRotateSprite(1,0);
}
else
{
dbSetSpriteFrame(1,2);
}
if(dbEscapeKey() == 1)
{
break;
}
dbSync ( );
}
}
However, I want my character to be able to move to the left right up and down. It would seem simple, however It isn't because I can't just copy this code and change the values to go left
if(dbRightKey() == 1)
{
dbRotateSprite(1,90);
dbPlaySprite(1,1,3,130);
dbMoveSprite(1,1);
dbRotateSprite(1,0);
}
else
{
dbSetSpriteFrame(1,2);
}
The reason behind this is because nothing will work right simply because their is multiple else statements which are supposed to act as key releases. Even when I take out all the else statements the code acts right but pauses on the wrong frame and also, for example, if i move my character to the right for a while but immediately try to move him to the left his animation takes a while to change to the left animation and continues to move when on the wrong animation because of the 130 delay.