I have successfully moved the sprite according to the key press. The problem is if the sprite is facing up, when you go left it cycles through the other frames before it faces left. The same goes with facing down and going right. Any fix for this? Or should I resort to using different image files of the same van?
link to
van.
#include "DarkGDK.h"
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
int x = 100, y = 200;
dbCreateAnimatedSprite(1, "van.png", 4, 1, 1);
dbSprite(1, x, y, 1);
// our main loop
while ( LoopGDK ( ) )
{
if ( dbEscapeKey ( ) )
return;
//key functions
if ( dbUpKey() ) {
dbPlaySprite(1, 1,1, 200);
dbSprite(1, x, y--, 1);
}
if ( dbDownKey() ) {
dbPlaySprite(1, 2,2, 200);
dbSprite(1, x, y++, 1);
}
if ( dbLeftKey() ) {
dbPlaySprite(1, 3,3, 200);
dbSprite(1, x--, y, 1);
}
if ( dbRightKey() ) {
dbPlaySprite(1, 4,4, 200);
dbSprite(1, x++, y, 1);
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}