Archived

This topic is now archived and is closed to further replies.

Creating a timer to display objects every few seconds.

This topic is 5305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I''m trying to create a timer to display an object every few seconds in my game world. I''ve been fooling around with high resolution timers but I can''t seen to get the timing to work. Any suggestions??

Share this post


Link to post
Share on other sites
I''m not exactly sure what your implimentation is, but I''m guessing your getting the time in milliseconds or something, and then using modulus to offset every 2 or 3 frames or so. what would work better is to keep a starting time variable, set it at the begging of an iteration, check each frame if the current time is greater than or equal to a constant (elapsed time) and then if it is greater or equal to draw your object, set that time as your start time, as repeat.

My Homepage

Share this post


Link to post
Share on other sites
Something like this?? This is my time function and the main render function

Time function

double World::RenderWeapon(Weapon* gameWeapons) // renders the weapon depending on the time

{
static float prevtime = this->worldTime.GetElapsedTime();
static float last = this->worldTime.GetElapsedTime();
double time;

if(worldTime.GetElapsedTime() - prevtime >= 3000) // testing for 3 seconds

{
gameWeapons->Draw(); // draw the weapon at the default location

prevtime = worldTime.GetElapsedTime(); // reset the timer

}

time = worldTime.GetElapsedTime() - last;
last = worldTime.GetElapsedTime();

return time;
}



This is the main render function that renders the objects

void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
gameWorld->RenderWeapon(gameWeapons); // draw the weapon

glPopMatrix();

// Draw Players

glPushMatrix();
P1->Draw();
glPopMatrix();

glPushMatrix();
P2->Draw();
glPopMatrix();
// end Draw Players


glutSwapBuffers();
}


This is just a preliminary layout of the code. Once I get things working I''ll make it more organized. The code as it is now doesn''t do the timing correctly.

Share this post


Link to post
Share on other sites