tamanho máximo de phaser de grupo ou piscina
function create ()
{
var Bullet = new Phaser.Class({
Extends: Phaser.GameObjects.Image,
initialize:
function Bullet (scene)
{
Phaser.GameObjects.Image.call(this, scene, 0, 0, 'bullet');
this.speed = Phaser.Math.GetSpeed(400, 1);
},
fire: function (x, y)
{
this.setPosition(x, y - 50);
},
update: function (time, delta)
{
this.y -= this.speed * delta;
if (this.y < -50)
{
this.setActive(false);
this.setVisible(false);
}
}
});
// Limited to just 4 objects in the pool, not allowed to grow beyond it
bullets = this.add.group({
classType: Bullet,
maxSize: 4,
runChildUpdate: true
});
ship = this.add.sprite(400, 500, 'ship').setDepth(1);
cursors = this.input.keyboard.createCursorKeys();
speed = Phaser.Math.GetSpeed(300, 1);
}
function update (time, delta)
{
if (cursors.left.isDown)
{
ship.x -= speed * delta;
}
else if (cursors.right.isDown)
{
ship.x += speed * delta;
}
if (cursors.up.isDown && time > lastFired)
{
var bullet = bullets.get();
if (bullet)
{
bullet.fire(ship.x, ship.y);
lastFired = time + 50;
}
}
}
Himanshu Jangid