Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

5 years ago by stahlmanDesign

I have a game timer that starts at 0 and counts up.

When I save my game, I save the ig.game.gameTimer.delta(); // 7.8 seconds

But when I reload the game, I cannot set the timer to where it was when saved, because it is always negative

Example:

ig.game.gameTimer.set(savedTime); // saved time = 7.8 but timer now starts counting up from -7.8

I tried setting it to a negative number but this doesn't seem to work

5 years ago by FelipeBudinich

It seems that you'll need to create your own timer that extends ig.Timer.

But you could try setting:

ig.Timer.time = savedTime;

I don't know which could be the side effects of this.

5 years ago by stahlmanDesign

Here's what I did to get around this.

Instead of setting the timer to a saved value:
ig.game.gameTimer.set(savedTime)

I save the value as a variable and reset the timer to zero. When the level is loaded, the timer starts at zero and I simply add the saved time to that.
// load saved game
...
ig.game.gameTimer.set(0);

elapsedTime = ig.game.gameTimer.delta() + savedTime;

5 years ago by FelipeBudinich

Doh! that is such a simple solution, genius :)
Page 1 of 1
« first « previous next › last »