Quote: "Why doesn't my background appear when the program starts?"
Because you don't display it inside the "while" loop. If a picture is displayed with dbPasteImage, then you need to paste it every loop, otherwise the next dbSync will make it disappear.
Quote: "how do I get my cursor to stay there instead of only appearing when you hold down the arrow key?"
Same as above, in this code you don't display the cursor if no key is pressed.
There is also another problem with this program. The code which displays your "title screen" and choices is inside the Dark GDK main loop. That means that after you have made the choice, this part will be executed again and again - well, unless you make other infinite "while" loops in your "play game" and "quit game" sections but that is not a very good design. This can be solved in two ways, either you put the title screen display before the main loop, or you introduce a "game state" variable and make a switch statement on it, to make sure that you execute only that code which is relevant to the current game state. See the Dark Invaders tutorial on how that is done.
The example below shows a code which executes the "title screen" and choice before the main loop. You can see that I used dbSprite to set the position of the pictures instead of dbPasteSprite and I made also the title screen a sprite. The advantage is that you don't need to paste them on the screen in every loop because a sprite defined with dbSprite will stay automatically on the screen and it is not erased by dbSync.
After the choice is done, the sprites and images are erased and you can start the Dark GDK loop, from which you can quit by pressing the ESC key. The "press ESC to exit" text that I put into the main loop is only for testing.
#include "DarkGDK.h"
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// load the image for the title screen
dbLoadImage ( "title.png", 1 );
dbSprite(1, 0, 0, 1);
dbCreateAnimatedSprite ( 2, "animatedcursor.png", 4, 4, 2 );
// default position of cursor sprite
int choice = 1;
dbSprite (2, 90, 361, 2);
do
{
if (dbRightKey ())
{
// quit option
dbSprite (2, 393, 360, 2);
choice = 2;
}
else if (dbLeftKey ())
{
// start option
dbSprite (2, 90, 361, 2);
choice = 1;
}
// animate cursor and update the screen
dbPlaySprite ( 2, 1, 16, 100 );
dbSync();
} while (! dbReturnKey());
// remove images and sprites used for the title screen
dbDeleteSprite(1);
dbDeleteSprite(2);
dbDeleteImage(1);
dbDeleteImage(2);
// our main loop
while ( LoopGDK ( ) )
{
dbText(0,0,"Press ESC to exit");
switch (choice)
{
case 1:
// play the game
break;
case 2:
// quit the game
break;
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}