Advertisement

Timer with minimal code

Started by July 15, 2000 09:18 PM
6 comments, last by jonnyfish 24 years, 5 months ago
This may sound like a complete newbie question, but how can I implement a timer with minimal code? I bascially want to have an update function called several times per second. Back in the days of djgpp w/ allegro, this would have been easy to implement, and with very little code. How can this be done in Windows?
Here is an example I found in a book.
    //1. In the header file, specify the ID of the timer.#define MY_TIMER 1//2. Create the timer.int nTimer = SetTimer(hWnd, MY_TIMER, 1000, NULL);//3. In the window procedure, process the timer messages.case WM_TILER: switch(wParam) {  case MY_TIMER:  //Do something here.  break; }break;    


This is not a very good way of doing it, but it is simple.





#define MY_LIFE BUSY

Edited by - The_C_Guy on July 15, 2000 11:17:11 PM
http://www.crosswinds.net/~druidgames/resist.jpg
Advertisement
or if you want to lock it.
    DWORD game_time;DWORD nTimel;while(!done){nTime=GetTickCount();...//game loop stuffwhile(GetTickCount()-nTime<33);//30 fps, can be changed}    


JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Thanks, that seemed to work nicely. I guess I wouldn''t have to ask newbie questions like this if I bought a few good books, but I prefer to waste all of my money on games
Make a timer class . Things will be very simple once your done with it - which really isn''t a hard task. I''ll send you one if you want it.

"Paranoia is the belief in a hidden order behind the visible." - Anonymous
dont suppose i could have a copy please staffan?

pete@jumblesoftware.com
jumble-----------
Advertisement
Right now, I''m only using this for a relatively small project (just a screensaver), and I really only needed one timer. But if I ever do anything more complex, I''ll make sure that everything is done with reusable classes (that''s what OOA/OOD/OOP is all about, right?)
quote: Original post by Staffan

Make a timer class . Things will be very simple once your done with it - which really isn't a hard task. I'll send you one if you want it.

"Paranoia is the belief in a hidden order behind the visible." - Anonymous


Is this class cross-platform?

I'm looking for something that's applicable whether I'm on Be, Linux, or DOS.

my email is wrenhal@juno.com


B e S
It's Da BOMB Baby!!!
<!-- It's Da BOMB Baby!!! -->

Edited by - wrenhal on July 17, 2000 4:28:08 PM
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka

This topic is closed to new replies.

Advertisement