Very N00b Question
Very N00b Question
Hi how would i go about adding a timer to my game. Id like it to be like mario so its a countdown timer and the remaining time goes on to the score.
Thankyou
Thankyou
-
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
If you actually think about how to do the timer yourself then you should be able to figure out how one would work using the value returned by the ITimer.
The value you get is either the time your system has been running or the time since a specific date many years ago (not sure which the irrlicht timer uses but it doesn't matter for this example).
So you've basically got some random time there, not the real time or anything, but it's all you need.
When you want to start your time you grab the current time from the timer and store it somewhere.
Then, you can compare the current time, each frame, with that time stamp you took and you'll know how many seconds have passed.
The value you get is either the time your system has been running or the time since a specific date many years ago (not sure which the irrlicht timer uses but it doesn't matter for this example).
So you've basically got some random time there, not the real time or anything, but it's all you need.
When you want to start your time you grab the current time from the timer and store it somewhere.
Then, you can compare the current time, each frame, with that time stamp you took and you'll know how many seconds have passed.
This will do what you want.
You can reset, pause the timer. And give you the time bewten resetets or if you pause it give you the add of all the time that has been not paused.
(kinda crhonometer).
How the irrlikcht device is acceded is your choice.
You also should clean the code .
And divide betwen 1000 to find the seconds.
You can reset, pause the timer. And give you the time bewten resetets or if you pause it give you the add of all the time that has been not paused.
(kinda crhonometer).
How the irrlikcht device is acceded is your choice.
Code: Select all
class MyTimer{
ITimer* timer;
unsigned long start;
unsigned long seconds;
bool stopped;
public:
MyTimer(){
timer = device->getTimer; //if you want, pass the device to the constructor
start = timer->getRealTime();
seconds = 0;
stopped = true;
};
void reset(){
seconds = 0;
start = timer->getRealTime();
stopped = true;
};
void pause(){
if(!stopped){
seconds = timer->getRealTime() - start + seconds;
stopped = true;
}
}
void play(){
if(stopped){
start = timer->getRealTime();
stopped = false;
};
}
unsigned long getTime(){
if (stopped)
return seconds;
return seconds+ timer->getRealTime()- start;
}
};
And divide betwen 1000 to find the seconds.
Thankyou for the code, ive got two errors though.
Error 1 error C3867: 'irr::IrrlichtDevice::getTimer': function call missing argument list; use '&irr::IrrlichtDevice::getTimer' to create a pointer to member
Error 2 error C2440: '=' : cannot convert from 'irr::ITimer *(__thiscall irr::IrrlichtDevice::* )(void)' to 'irr::ITimer *'
Error 1 error C3867: 'irr::IrrlichtDevice::getTimer': function call missing argument list; use '&irr::IrrlichtDevice::getTimer' to create a pointer to member
Error 2 error C2440: '=' : cannot convert from 'irr::ITimer *(__thiscall irr::IrrlichtDevice::* )(void)' to 'irr::ITimer *'
By the way. I think anyway what he want can be done in a accuracy way in irlicht.
Because what he would want is a function callbacked for dx time.
I used this in allegro library(2d). You could attach some function callback to a timer.Then that function wuoul be invocated each dx time.
How can be this resolved?.
If I undertand correcly( If I remember correctly ) in allegro the timer gerated a interruption that were handled for the function that you use as callback. But realy I don't know how to to this in irrlicht.
This nooby question has grow up .
Any ideas?
Because what he would want is a function callbacked for dx time.
I used this in allegro library(2d). You could attach some function callback to a timer.Then that function wuoul be invocated each dx time.
How can be this resolved?.
If I undertand correcly( If I remember correctly ) in allegro the timer gerated a interruption that were handled for the function that you use as callback. But realy I don't know how to to this in irrlicht.
This nooby question has grow up .
Any ideas?