how in c++ would i make a function that incremented a value by 1 at a set amount of seconds... say .001 seconds it increments x by 1
i dont know of any functions that do this, and im just learning to program....
any help is appreciated
-sysFA1L
if you''re in dos you would have to use the timer interrupt istself
i don''t come up with any other accurate ideas
and if you''re in windows
you can use SetTimer
or multimedia timer which are better
Arkon
[QSoft Systems]
i don''t come up with any other accurate ideas
and if you''re in windows
you can use SetTimer
or multimedia timer which are better
Arkon
[QSoft Systems]
Timing is a piece of cake in C++. Here''s an example:
// Example of timing using Win32 APIclass Timer{public: Timer(DWORD Rate, void (* OnTime)()) ~Timer(); bool Update();private: DWORD Rate; void (* OnTimePtr)(); };Timer::Timer(DWORD Rate, void (* OnTime)()) : Rate(Rate){ OnTimePtr = OnTime; }Timer::~Timer(){}bool Timer::Update(){ static DWORD time = timeGetTime(); if (timeGetTime() - time >= Rate) { time = timeGetTime(); if (OnTimePtr) OnTimePtr(); return true; } return false;}// OnTimer function void IcrementOnOneSecond(){ ++somevar;}// Then in a class or somewhere:Timer timer(1000, IncrementOnOneSecond); // Create a new timer for 1 second// Then in the game/app loop or update area:timer.Update(); // Which checks time state and calls our init function
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement