bp74 / StageXL

A fast and universal 2D rendering engine for HTML5 and Dart.
http://www.stagexl.org
Other
882 stars 82 forks source link

Suggestion: Time scale #266

Open Tomucha opened 7 years ago

Tomucha commented 7 years ago

Hi!

I would like to have "double timeScale" property in RenderLoop. I want player to be able to speed game up or slow it down. It seems to me that this would be pretty straight forward change. Right here:

https://github.com/bp74/StageXL/blob/master/lib/src/display/render_loop.dart#L47

Just multiply deltaTime by timeScale, IMHO.

bp74 commented 7 years ago

Hi Tomas,

Do you use the Juggler? You could do something like this:

class TimeLapseJuggler extends Juggler {
  num speed = 2.0;
  bool advanceTime(num time) {
    super.advanceTime(time * speed);
  }
}

var myJuggler = new TimeLapseJuggler();
renderloop.juggler.add(myJuggler);

Now you use this juggler for all your animations. You can also change the the "speed" property to change the speed of the playback.

bp74 commented 7 years ago

Btw. this is the prefered technique to implement a "pause" button. You use your own instance of Juggler and if you want to pause the game, you just remove your juggler from the main juggler.

// pause
renderloop.juggler.remove(myJuggler);

// continue
renderloop.juggler.add(myJuggler);
Tomucha commented 7 years ago

Good tip, thanks!

I don't like keeping my own reference to my specialised Juggler, because anyone can call "stage.juggler" and "escape my time scale". Please consider allowing me to create RenderLoop instance with my own "root" Juggler in constructor.

In my case I have overridden RenderLoop itself so I can have this "time scale" behaviour global. (My UI isn't in StageXL, so I don't need any exceptions from this global time scale, and I want to make sure that everything respect it.)

Anyway, thanks again!