phaser/wip/components/UpdateManager.js
2018-01-09 22:12:16 +00:00

79 lines
1.4 KiB
JavaScript

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Dirty! Manager
*
* @class
*/
Phaser.UpdateManager = function (state)
{
this.state = state;
this.game = state.game;
this.list = [];
// this.i = 1;
this.running = false;
this.processed = 0;
};
Phaser.UpdateManager.prototype.constructor = Phaser.UpdateManager;
Phaser.UpdateManager.prototype = {
stop: function ()
{
if (!this.running)
{
return;
}
// console.log(this.i, 'UpdateManager.stop', this.processed);
this.list.length = 0;
// this.i++;
},
start: function ()
{
if (!this.running)
{
return;
}
var len = this.list.length;
if (len === 0)
{
return;
}
// console.log(this.i, 'UpdateManager.start', len);
this.processed = 0;
for (var i = 0; i < len; i++)
{
// Because it may have already been processed (as a child of another Transform that was updated)
if (this.list[i] && this.list[i]._dirty)
{
this.processed++;
this.list[i].update();
}
}
},
add: function (transform)
{
this.list.push(transform);
}
};