mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 19:43:28 +00:00
49 lines
1,001 B
JavaScript
49 lines
1,001 B
JavaScript
|
// 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 ()
|
||
|
{
|
||
|
var gameObject = new this.classType(this.state, 0, 0, this.defaultKey, this.defaultFrame);
|
||
|
|
||
|
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;
|