I have the following code in phaser, and I want to use a sprite animation instead of a static image, how can I pull that off? Using group to create new bullets. I am creating a new object and with that creating new bullets to get fired by the player. And I want the bullet to rotate with an animated spritshit. How can I do that?
this.bullets = this.physics.add.group({
classType: Bullet,
maxSize: 10,
runChildUpdate: true,
});
The class i am using to create new bullets
var Bullet = new Phaser.Class({
Extends: Phaser.GameObjects.Image,
initialize:
function Bullet (scene)
{
Phaser.GameObjects.Sprite.call(this, scene, 0, 0, "bullet");
this.speed = Phaser.Math.GetSpeed(250, 1);
},
fire: function (x, y, direcao)
{
this.direcao = direcao;
if(direcao == 1){
//Cima
// console.log("Tiro Acima");
this.setPosition(x, y - 10);
this.setActive(true);
this.setVisible(true);
}else if(direcao == 2){
// Baixo
// console.log("Tiro Abaixo");
this.setPosition(x, y + 10);
this.setActive(true);
this.setVisible(true);
}else if(direcao == 3){
//Direita
//console.log("Tiro a direita");
this.setPosition(x + 10, y);
this.setActive(true);
this.setVisible(true);
}else if(direcao == 4){
//Esquerda
//console.log("Tiro a esquerda");
this.setPosition(x - 10, y );
this.setActive(true);
this.setVisible(true);
} else {
//Debug
console.log("Não disparou");
}
},
update: function (time, delta)
{
if(this.direcao == 1){
//Cima
// console.log("Tiro Acima");
this.y -= this.speed * delta;
}else if(this.direcao == 2){
//Baixo
// console.log("Tiro Abaixo");
this.y += this.speed * delta;
}else if(this.direcao == 3){
//Direita
// console.log("Tiro a direita");
this.x += this.speed * delta;
}else if(this.direcao == 4){
//Esquerda
// console.log("Tiro a esquerda");
this.x -= this.speed * delta;
}else{
//Debug
// console.log("Não disparou");
}
if (this.y < 0)
{
this.setActive(false);
this.setVisible(false);
}
if (this.y > 480)
{
this.setActive(false);
this.setVisible(false);
}
if (this.x < 0)
{
this.setActive(false);
this.setVisible(false);
}
if (this.x > 960)
{
this.setActive(false);
this.setVisible(false);
}
}
});