Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Timer that does something?

Tags:

c#

xna

I'm quite new in XNA C# and I would like to know how do I create a timer in XNA C# that does something after few seconds.

I've seen a Flash tutorial that does what I need but I don't know how to do it in XNA C#

I'm trying to use a timer to make a blinking model in certain period of my project. Therefore, I need to know how do I start the timer and how does the timer toggle the blinking of my model.

Thanks.

like image 270
Zainu Avatar asked May 03 '26 07:05

Zainu


1 Answers

Do something like below in update

float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

then have a variable for seconds like

float timer = 5.0f; // Five seconds

then in update

timer -= elapsedTime

if(timer <= 0)
{
    // Hanlde the blink here
    timer = 5.0f; // Reset timer
} 
like image 139
Mike Avatar answered May 05 '26 21:05

Mike