пулевый механизм в фазере
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);
this.setActive(true);
this.setVisible(true);
},
update: function (time, delta)
{
this.y -= this.speed * delta;
if (this.y < -50)
{
this.setActive(false);
this.setVisible(false);
}
}
});
bullets = this.add.group({
classType: Bullet,
maxSize: 10,
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