2 Replies - 11220 Views - Last Post: 14 March 2010 - 09:19 AM

#1 UofMCreed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 04-October 08

Timing Events in XNA

Posted 12 March 2010 - 01:18 AM

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!

Is This A Good Question/Topic? 0
  • +

Replies To: Timing Events in XNA

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

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.

            // 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
            }


Was This Post Helpful? 2
  • +
  • -

#3 Hellbroth  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 189
  • Joined: 15-August 09

Re: Timing Events in XNA

Posted 14 March 2010 - 09:19 AM

View PostSixOfEleven, 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.

            // 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1