I hope this helps...
/** @file Main.cpp */
#include <dinput.h>
#include "DarkGDK.h"
#define TICK_TIME 100 // AI will be given time to "think" every 100ms (10 times per second)...
#define MAX_TICKS 10 // AI will be allowed to make up a maximum of 10 "think" cycles at a time...
#define STR_LENGTH 100 // Maximum string length for status messages on screen...
/**
Load the bitmaps, sprites, objects and meshes we will need.
@return bool - true if successful; otherwise, false.
*/
bool LoadDisplayResources(void)
{
dbCreateAnimatedSprite(1, "Clubs_Rotation.png", 9, 1, 1);
dbHideSprite(1);
return true;
}
/**
Determines whether or not we can actually render graphics.
@return bool - true if successful; otherwise, false.
*/
bool CanRender(void)
{
if (dbSpriteExist(1))
return true;
return LoadDisplayResources();
}
/**
Main entry point to the application.
*/
void DarkGDK ( void )
{
bool fullscreen=false;
bool alt_key=false;
bool enter_key=false;
char fps[20];
int tick_start, tick_end; // Timer values used to determine AI "think" cycles...
int num_ticks, frame_time; // How many AI "think" cycles were handled and time required...
char fps_string[STR_LENGTH]; // Used to show screen FPS rates...
int frame_number=0;
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn();
dbSyncRate(0);
dbSetDisplayModeVSync(640,480,32,0);
dbSetWindowOn();
LoadDisplayResources();
// our main loop
tick_start=dbTimer();
while ( LoopGDK ( ) )
{
num_ticks=frame_time=0;
tick_end=dbTimer(); // Is it time for the AI to "think"...? If so then let it do so...
while (((tick_end-tick_start)>TICK_TIME) && (num_ticks<MAX_TICKS))
{
frame_number++;
if (frame_number>8)
frame_number=0; // zero based image indexing...
dbSetSpriteFrame(1,frame_number); // projectile instance needs to think...
tick_start+=TICK_TIME;
frame_time+=TICK_TIME;
++num_ticks;
}
// Is the [ALT+ENTER] key combination in effect...?
alt_key=(dbKeyState(DIK_LMENU) || dbKeyState(DIK_RMENU));
enter_key=(dbKeyState(DIK_RETURN));
if (alt_key && enter_key)
{
// Toggle between fullscreen / windowed mode...
if (fullscreen)
{
dbSetWindowOn();
fullscreen=false;
}
else
{
dbSetWindowOff();
fullscreen=true;
}
}
if (CanRender())
{
sprintf_s(fps_string, STR_LENGTH, "FPS: %d", dbScreenFPS());
dbText( dbScreenWidth() - 150, 0, fps_string);
dbPasteSprite(1, 0, 0);
dbSync ( );
}
}
// return back to windows
return;
}
As I've said, I don't care to use the dbPlaySprite() because I really don't know what the timer-value represents. Using this method, I can set the animation to any speed I want by changing the TICK_TIME value at the top. The way it is, it will do one full animation cycle every 9/10th's of a second.
Additionally, this code illustrates a *way* to toggle between fullscreen / window'd mode - on the fly (I'd like to thank
dark coder for this bit as it really is the easiest way).
Furthermore, it shows a loop that will
Decouple the Display loop from the Game Loop.
All of which are *proverbial* standard techniques that I've adopted and offer to you for your perusal (and use if you like)...
Regards,
JTK
EDIT: The image used in this example is a saved version of the image provided in the post above.