Greetings all. Im finally getting to the point were im learning to develop games in XNA. Im working on a project of my own now and am having some difficulty locating the information i need. What I want to do is basicaly very simple, I have a ship to control and it can drop up too 10 bombs at a time, each individual bomb can only last 15sec before they explode.
THE PROBLEM:
Im having a hard time locating the information i need for timing events. I have no idea how to implement time, how to keep track of it etc. etc. I dont know how to code my bombs to blow up after 15sec. I know and understand that code is needed, but im in the position were I have no idea how to begin to work with this.
So I was wondering if someone could point me in the right direction via some links, or some sample code. I scanned through the forum already and didnt notice anything about time event handling. Can someone plz help guide me through this!?
Much appreciated for your time!
Timing Events in XNA
Page 1 of 12 Replies - 11220 Views - Last Post: 14 March 2010 - 09:19 AM
Replies To: Timing Events in XNA
#2
Re: Timing Events in XNA
Posted 12 March 2010 - 06:36 AM
I find the TimeSpan struct the easiest way to keep track of time with XNA. It isn't the only way but I like it the most. Would you would do is create a TimeSpan object to hold the elapsed time you want to check. In the Update method you use the gameTime parameter to add elapsed time to the TimeSpan object you created. The gameTime parameter has two properties: ElapsedGameTime and ElapsedRealTime. They both measure in milliseconds the elapsed time in the game since the last call to the Update method but are slightly different.
You can use either elapsed game time or elapsed real time for keeping track of it. You can use something like the following to track time.
You can use either elapsed game time or elapsed real time for keeping track of it. You can use something like the following to track time.
// Class field
TimeSpan bombTimer = TimeSpan.Zero;
// In your Update method
bombTimer += gameTime.ElapsedGameTime;
// bombTimer += gameTime.ElapsedRealTime;
if (bombTimer > TimeSpan.FromSeconds(15))
{
// 15 seconds have elapsed handle what you wanted to do
}
#3
Re: Timing Events in XNA
Posted 14 March 2010 - 09:19 AM
SixOfEleven, on 12 March 2010 - 05:36 AM, said:
I find the TimeSpan struct the easiest way to keep track of time with XNA. It isn't the only way but I like it the most. Would you would do is create a TimeSpan object to hold the elapsed time you want to check. In the Update method you use the gameTime parameter to add elapsed time to the TimeSpan object you created. The gameTime parameter has two properties: ElapsedGameTime and ElapsedRealTime. They both measure in milliseconds the elapsed time in the game since the last call to the Update method but are slightly different.
You can use either elapsed game time or elapsed real time for keeping track of it. You can use something like the following to track time.
You can use either elapsed game time or elapsed real time for keeping track of it. You can use something like the following to track time.
// Class field
TimeSpan bombTimer = TimeSpan.Zero;
// In your Update method
bombTimer += gameTime.ElapsedGameTime;
// bombTimer += gameTime.ElapsedRealTime;
if (bombTimer > TimeSpan.FromSeconds(15))
{
// 15 seconds have elapsed handle what you wanted to do
}
Thanx realy helped me.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote




|