phaser/wip/components/UpdateManager.js

80 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* @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 = [];
2016-10-14 07:58:12 +00:00
2016-11-01 01:19:32 +00:00
// this.i = 1;
2016-10-14 07:58:12 +00:00
this.running = false;
this.processed = 0;
};
2016-10-14 07:58:12 +00:00
Phaser.UpdateManager.prototype.constructor = Phaser.UpdateManager;
2016-10-14 07:58:12 +00:00
Phaser.UpdateManager.prototype = {
2016-10-14 07:58:12 +00:00
stop: function ()
{
2016-10-14 07:58:12 +00:00
if (!this.running)
{
return;
}
// console.log(this.i, 'UpdateManager.stop', this.processed);
this.list.length = 0;
2016-10-14 07:58:12 +00:00
2016-11-01 01:19:32 +00:00
// this.i++;
},
2016-10-14 07:58:12 +00:00
start: function ()
{
2016-10-14 07:58:12 +00:00
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);
}
};