2017-07-07 17:14:58 +00:00
|
|
|
// Phaser.GameObjects.SpritePool
|
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Sprite = require('../sprite/Sprite');
|
|
|
|
var ObjectPool = require('./ObjectPool');
|
|
|
|
|
|
|
|
// An Object Pool
|
|
|
|
|
|
|
|
var SpritePool = new Class({
|
|
|
|
|
|
|
|
Extends: ObjectPool,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function SpritePool (manager, maxSize, quantity, key, frame)
|
|
|
|
{
|
|
|
|
ObjectPool.call(this, manager, Sprite, maxSize, this.makeSprite, this);
|
|
|
|
|
|
|
|
this.defaultKey = key;
|
|
|
|
|
|
|
|
this.defaultFrame = frame;
|
|
|
|
},
|
|
|
|
|
|
|
|
makeSprite: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
var gameObject = new this.classType(this.scene, 0, 0, this.defaultKey, this.defaultFrame);
|
2017-07-07 17:14:58 +00:00
|
|
|
|
|
|
|
this.displayList.add(gameObject);
|
|
|
|
this.updateList.add(gameObject);
|
|
|
|
|
|
|
|
gameObject.setActive(false);
|
|
|
|
gameObject.setVisible(false);
|
|
|
|
|
|
|
|
return gameObject;
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function (x, y)
|
|
|
|
{
|
|
|
|
var gameObject = this.getFreeGameObject();
|
|
|
|
|
|
|
|
gameObject.setPosition(x, y);
|
|
|
|
|
|
|
|
return gameObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = SpritePool;
|