Game Development Community

CountDown Timer?

by GxG6(Mark-Anthony) · in Torque X 2D · 09/30/2010 (1:38 pm) · 12 replies

Whats the proper way to go about making a Countdown Timer, similar to the
ones in puzzle games/triva games?
I searched the forums but I end up finding posts related to server/client side timers or TGEA, I was somethings about using the schedule function, but I have no idea how to go about it.

#1
09/30/2010 (11:59 pm)
Throw this in your Game.cs:
public TimeSpan CountDownTime { get; set; }

Now register the time to count down from:
int hours = 0;
            int minutes = 10;
            int seconds = 30;
            Game.Instance.CountDownTime = new TimeSpan(hours, minutes, seconds);

Put this in your ProcessTick:
Game.Instance.CountDownTime -= Game.Instance.Engine.GameTime.ElapsedGameTime;

Now display "Game.Instance.CountDownTime" on the screen like you would any other text.

Want to only display Minutes and Seconds? Set your GUIText to this:

"Time: " + Game.Instance.CountDownTime.Minutes + ":" + Game.Instance.CountDownTime.Seconds;

P.S. Not sure if its "Proper" but it seems to work :-)

Aaron
#2
10/01/2010 (12:30 am)
thank you for your reply i knew nothing about this method, I will test it out when I get the chance, thank you again
#3
10/01/2010 (8:14 am)
I learn, You learn, We all learn. No Problem :-) What type of game are you making?
#4
10/03/2010 (1:37 pm)
its a puzzle game
question:
ok so I did your approach but I don't think I put it in the right areas. When I run my program it will show the time, but It doesn't countdown at all.
Shouldn't the whole code go into my gui class so that when a new level is loaded the time will run with it?

And you are correct it is a great sign for a community when we all are able to learn from each other and help each other :-)
#5
10/03/2010 (6:17 pm)
Game.Instance.CountDownTime -= Game.Instance.Engine.GameTime.ElapsedGameTime;
In my test run, I threw this into my movement components ProcessTick.

You can locate it anywere, but it needs to be updated constantly. If you have it inside your processTick and it's still not working, make sure the ProcessTick has been initiated.

If you are using a component, add this to _OnRegister() to initiate the ProcessTick
ProcessList.Instance.AddTickCallback(Owner, this);

After you get it working:

If you want to delay the countdown you could setup a bool and check it
if (_clockOn)
            {
                Game.Instance.CountDownTime -= Game.Instance.Engine.GameTime.ElapsedGameTime;
            }

Define _clockOn
bool _clockOn = false;


When you want to start the countdown set _clockOn to True
_clockOn = true;

Do you freelance your artwork? If so, you mind sending me some examples? I'm looking for an artist.
#6
10/05/2010 (3:02 pm)
I haven't freelanced, yet still trying to get everything up and running again, but gameart wise i believe i need to work on more. if you interested my back-up portfolio its here: http://yashiro-vibez.deviantart.com/

I will try what you said when i get home, thanks
#7
10/05/2010 (5:18 pm)
Awesome this could be on TDN.
#8
10/05/2010 (10:05 pm)
Hey I like to be the first well second to say Thank You For a Very simple Appoarch, its unbelievable how hard it is to search for things on this site lol, so many unanswered questions, not to mention us torqueX users only have 1 book to go by and its now dated and doesn't cover much.

anyway I agree with John Bura, You should submit this to TDN :)

p.s. it was because I didn't register the processtick, I put the clock in its one class (duh* slaps self*)
Let me know what you think of the art you see, I am going to be working more on my game art now that the programming is mostly done.
#9
10/05/2010 (10:41 pm)
oh 1 last question

lets say I want to start or stop the clock from outside the component its in.

Would I use a format like this:

MovementCompnent st = new MovementCompnent();
            st._Clockon = True;

or

MovementCompnent st =                    Owner.Components.FindComponent<MovementCompnent>();

st._Clockon = True;

?
#10
10/06/2010 (4:29 am)
Thanks Guys! I will write it up for the TDN :-)

I have a hand full of other cool goodies that I will be sharing, stay tuned :-)

@Mark: The second one will do the trick :-)
MovementComponent st = Owner.Components.FindComponent<MovementComponent>();
st._clockOn = true;
#11
10/10/2010 (11:18 am)
ahhhh thanks I believe I'm finally getting a hang of this torque X I just wish there were more books, that go indepth

And I will Download every thing you add to the TDN LOL
#12
12/08/2010 (4:10 pm)
Hey Thanks for that Aaron. It came in handy.