Sign in to follow this  
ProjectOlle

XNA gametime question

Recommended Posts

Hey guys!

I'm making a tower-defense like game and need some cooldown on the shots from the towers so they wont just spam out shots in more or less a straight line. Im still pretty new to XNA so could anyone tell me how I compare time ? ..

I would like to do something like:
Shoot(); // every 5 sec

Thx in advance! :D

Share this post


Link to post
Share on other sites
See this as an example of how to compare time: [url="http://blogs.msdn.com/b/shawnhar/archive/2007/06/08/displaying-the-framerate.aspx"]http://blogs.msdn.co...-framerate.aspx[/url]

In your case you could do:
[code]
elapsedTime += gameTime.ElapsedGameTime;
if (elapsedTime > TimeSpan.FromSeconds(5))
{
elapsedTime -= TimeSpan.FromSeconds(5);
//--Event at 5 seconds
}
[/code]

Share this post


Link to post
Share on other sites
[quote name='UltimaX' timestamp='1302527512' post='4797103']
See this as an example of how to compare time: [url="http://blogs.msdn.com/b/shawnhar/archive/2007/06/08/displaying-the-framerate.aspx"]http://blogs.msdn.co...-framerate.aspx[/url]

In your case you could do:
[code]
elapsedTime += gameTime.ElapsedGameTime;
if (elapsedTime > TimeSpan.FromSeconds(5))
{
elapsedTime -= TimeSpan.FromSeconds(5);
//--Event at 5 seconds
}
[/code]
[/quote]
<3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this