I plan to do some sprite animation, and obviously it will require timing of some sort for the frames and movement of the sprites. I am aware of two methods to perform timing, though I'm sure there are others. I have seen it stated many times that Settimer is not the most accurate implementation, if not difficult to work with. I was wondering if it is possible/ advised to implement two seperate Settimer events to control both frame speed and movement speed respectively.
My program will not have more than about 8 instances of a 28-frame sprite on-screen at any given time. With this in mind, is there really any advantage to using a multimedia timer? And by extension, what would be an example of a program that would be better off with a multimedia timer?
Below is a basic multimedia timer example I found on the net. It doesn't do anything special, but maybe it can be of some use to people who are looking for one. This is my C version with some changes. Where would I put the code if using this method? I suppose that it isn't handled in WM_TIMER?
#include <windows.h>
#include <stdio.h>
void CALLBACK TimeProc ( UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 )
{
printf("waiting\n");
}
int main( void )
{
UINT uDelay = 1000; //period between each occurance of an event
UINT uResolution = 1; //precision
DWORD dwUser = NULL; // User instance data
UINT fuEvent = TIME_PERIODIC; //You also choose TIME_ONESHOT;
MMRESULT FTimerID;
timeBeginPeriod( 1 );
FTimerID = timeSetEvent(uDelay, uResolution, TimeProc, dwUser, fuEvent);
if(FTimerID==NULL){printf("Failed to generate multimedia timer.\n");}
Sleep( 10000 ); //how long the timer runs for
timeKillEvent( FTimerID );
timeEndPeriod( 1 );
return 0;
}
