I had to change some of the code simply because I don't have your graphics and I don't have time to put one together. The code below works, without background since I commented it out. I'm seeing what seem to me to be some inconsistencies that I'll point out and let you determine if they're so.
You're doing a dbCreateAnimatedSprite and assigning the image number 2. Yet when you dbPlaySprite and dbSprite you reference image 1. Maybe I'm overlooking something.
#include "DarkGDK.h"
void GameStart (void);
// the main entry point for the application is this function
void DarkGDK ( void )
{
while ( LoopGDK ( ) )
{
//TitleScreen();
GameStart();
// update the screen
dbSync ( );
}
return;
}
void GameStart ()
{
dbHideMouse ( );
int mX = 10;
int mY = 200;
dbLoadImage("c:\\myship.png", 1);
// dbCreateAnimatedSprite ( 1, "mmwalks.png", 11, 1, 2 );
// dbPlaySprite ( 1, 1, 11, 80 );//look at 9
dbSprite ( 1, mX, mY, 1 );
while ( dbLeftKey() || dbRightKey() )
{
if ( dbLeftKey() == 1 )
{
// dbLoadBitmap ( "space.png" );
dbSprite ( 1, --mX, mY, 1 );
// dbPlaySprite ( 1, 1, 11, 80 );
// dbControlCameraUsingArrowKeys ( 3, mX--, 1 );
}
else if ( dbRightKey() == 1 )
{
// dbLoadBitmap ( "space.png" );
dbSprite ( 1, ++mX, mY, 1 );
// dbPlaySprite ( 1, 1, 11, 80 );
// dbControlCameraUsingArrowKeys ( 3, mX++, 1 );
}
dbSync();
}
//dbSprite ( 3, 0, 100, 3 );
//dbCreateAnimatedSprite (3, "Nova.png", 1, 1, 3);
//dbPlaySprite ( 3, 1, 1, 100 );
dbLoadBitmap ( "space.png" );//psp dimensions "pspspace.png
//dbSetCameraToImage ( 3, 1, 400, 400 );
}
I changed the mX++ and mX-- to ++mX and --mX respectively. C/C++ has prefix and postfix incrementation/decrement. When you say mX++ the program will use the current value of mX and at some point before the statement is completed will increment mX. If you say ++mX the value of mX is incremented and then the value is used in the expression.
Now, as shown above, substituting my own graphic, the sprite will move right as long as I hold the right arrow key down. Ditto for the left arrow key. If I hold one down while switching to the other I can move back and forth, though the left arrow key takes precedence.
As soon as I release the keys the sprite snaps back to its default position. Here's what's happening. GameStart() is called over and over again. It's inside the
while (LoopGDK())
loop. So when you release the key GameStart () exits but the outside loop calls it back up again and the first thing that it does is reset mX and mY back to their starting positions.
I've moved the dbSync to the end of the function since you want to sync after you've changed the position. Visually it doesn't make much difference but it might cause a problem later that requires debugging.
Although I haven't done it in the code above, I'd take the dbLoadBitmap calls out of the if statements and make only one call to it at the beginning of the loop.
You probably want to also do some tests to make sure that mX never goes below 0 or above the width of the screen less the width of the sprite.
Lilith, Night Butterfly
I'm not a programmer but I play one in the office