Using GameTime in a new class.

Hi there.

I’m trying to write a small GameTime class for handling in game timers. In theory it should make life a little bit easier and give me a bit more control without getting the main blocks of code too messy.

But, I can’t seem to get GameTime working in said class. I have something like:
Private gt as GameTime
gt = New GameTime

and a few simple properties for returning the elapsed time since the last check and the total game time for testing,but gt (GameTime) only ever returns 0.

Can there only be one GameTime? Or how can I create/use the GameTime in classes other then the main?

Thanks.

You should update your timer manager every frame using the GameTime passed to Game1.Update. The GameTime class in itself just holds the time data, the values are updated in the Game class.

Yeah, that’s all ok and working fine. What I was trying to do was create a Timer class to help clean up variables around timing events, so instead of every event having 2 variables I could just call a check on a class instance. But GameTime doesn’t produce a value outside of Game1.

Is there a way to make another class aware of GameTime?

Thanks Jjagg.

not in a elegant way. You cold have it by making a static variable on game1 and setting it every update. But you would be best just passing it as a parameter.

I’m my games I have a variable dt. I get the time passes since last update and store it in dt then I pass that in to all my classes.