mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Game.step now uses more events and less direct calls.
This commit is contained in:
parent
d595da49fd
commit
ade37dd35e
1 changed files with 33 additions and 36 deletions
|
@ -25,10 +25,6 @@ var TextureManager = require('../textures/TextureManager');
|
|||
var TimeStep = require('./TimeStep');
|
||||
var VisibilityHandler = require('./VisibilityHandler');
|
||||
|
||||
/**
|
||||
* @callback GameStepCallback
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible
|
||||
|
@ -237,17 +233,6 @@ var Game = new Class({
|
|||
*/
|
||||
this.plugins = new PluginManager(this, this.config);
|
||||
|
||||
/**
|
||||
* The `onStepCallback` is a callback that is fired each time the Time Step ticks.
|
||||
* It is set automatically when the Game boot process has completed.
|
||||
*
|
||||
* @name Phaser.Game#onStepCallback
|
||||
* @type {GameStepCallback}
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.onStepCallback = NOOP;
|
||||
|
||||
/**
|
||||
* Is this Game pending destruction at the start of the next frame?
|
||||
*
|
||||
|
@ -335,10 +320,12 @@ var Game = new Class({
|
|||
|
||||
VisibilityHandler(this.events);
|
||||
|
||||
this.events.on('hidden', this.onHidden, this);
|
||||
this.events.on('visible', this.onVisible, this);
|
||||
this.events.on('blur', this.onBlur, this);
|
||||
this.events.on('focus', this.onFocus, this);
|
||||
var eventEmitter = this.events;
|
||||
|
||||
eventEmitter.on('hidden', this.onHidden, this);
|
||||
eventEmitter.on('visible', this.onVisible, this);
|
||||
eventEmitter.on('blur', this.onBlur, this);
|
||||
eventEmitter.on('focus', this.onFocus, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -385,33 +372,43 @@ var Game = new Class({
|
|||
return this.runDestroy();
|
||||
}
|
||||
|
||||
// Global Managers
|
||||
var eventEmitter = this.events;
|
||||
|
||||
this.plugins.update(time, delta);
|
||||
// Global Managers like Input and Sound update in the prestep
|
||||
|
||||
this.input.update(time, delta);
|
||||
eventEmitter.emit('prestep', time, delta);
|
||||
|
||||
this.sound.update(time, delta);
|
||||
// This is mostly meant for user-land code and plugins
|
||||
|
||||
// Scenes
|
||||
eventEmitter.emit('step', time, delta);
|
||||
|
||||
this.onStepCallback();
|
||||
// Update the Scene Manager and all active Scenes
|
||||
|
||||
this.scene.update(time, delta);
|
||||
|
||||
// Render
|
||||
// Our final event before rendering starts
|
||||
|
||||
eventEmitter.emit('poststep', time, delta);
|
||||
|
||||
var renderer = this.renderer;
|
||||
|
||||
// Run the Pre-render (clearing the canvas, setting background colors, etc)
|
||||
|
||||
renderer.preRender();
|
||||
|
||||
this.events.emit('prerender', renderer);
|
||||
eventEmitter.emit('prerender', renderer, time, delta);
|
||||
|
||||
// The main render loop. Iterates all Scenes and all Cameras in those scenes, rendering to the renderer instance.
|
||||
|
||||
this.scene.render(renderer);
|
||||
|
||||
// The Post-Render call. Tidies up loose end, takes snapshots, etc.
|
||||
|
||||
renderer.postRender();
|
||||
|
||||
this.events.emit('postrender', renderer);
|
||||
// The final event before the step repeats. Your last chance to do anything to the canvas before it all starts again.
|
||||
|
||||
eventEmitter.emit('postrender', renderer, time, delta);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -434,23 +431,25 @@ var Game = new Class({
|
|||
*/
|
||||
headlessStep: function (time, delta)
|
||||
{
|
||||
var eventEmitter = this.events;
|
||||
|
||||
// Global Managers
|
||||
|
||||
this.input.update(time, delta);
|
||||
eventEmitter.emit('prestep', time, delta);
|
||||
|
||||
this.sound.update(time, delta);
|
||||
eventEmitter.emit('step', time, delta);
|
||||
|
||||
// Scenes
|
||||
|
||||
this.onStepCallback();
|
||||
|
||||
this.scene.update(time, delta);
|
||||
|
||||
eventEmitter.emit('poststep', time, delta);
|
||||
|
||||
// Render
|
||||
|
||||
this.events.emit('prerender');
|
||||
eventEmitter.emit('prerender');
|
||||
|
||||
this.events.emit('postrender');
|
||||
eventEmitter.emit('postrender');
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -595,8 +594,6 @@ var Game = new Class({
|
|||
this.renderer.destroy();
|
||||
}
|
||||
|
||||
this.onStepCallback = null;
|
||||
|
||||
if (this.removeCanvas && this.canvas)
|
||||
{
|
||||
CanvasPool.remove(this.canvas);
|
||||
|
|
Loading…
Reference in a new issue