Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created October 11, 2015 14:40
Show Gist options
  • Save joseph-montanez/6ca191476beb4b17b685 to your computer and use it in GitHub Desktop.
Save joseph-montanez/6ca191476beb4b17b685 to your computer and use it in GitHub Desktop.
How I am pausing the physics engine
function pause() {
FamousEngine.renderLoop.stop();
_SceneTwo.paused = true;
}
function resume() {
FamousEngine.renderLoop.start();
_SceneTwo.paused = false;
}
var updateLoop = appNode.addComponent({
state: 'running',
timeLastPaused: null,
timeAfterPaused: null,
onUpdate: function(time) {
if (_SceneTwo.paused && this.state == 'running') {
this.timeLastPaused = clock.getTime();
this.state = 'paused';
}
if (_SceneTwo.paused && this.state != 'running') {
this.timeAfterPaused = time;
}
if (!_SceneTwo.paused && this.state != 'running') {
this.state = 'running';
}
if (this.timeLastPaused != null && this.timeAfterPaused != null) {
time = this.timeLastPaused + (time - this.timeAfterPaused);
}
if (!_SceneTwo.paused) {
_SceneTwo.world.update(time);
//.. do logic stuff here
}
FamousEngine.requestUpdateOnNextTick(this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment