import Phaser from 'phaser'
export default class Gob extends Phaser.Physics.Arcade.Sprite
{
private target: Phaser.Physics.Arcade.Sprite
moveItems(object: this, speed: number): void
{
object.y += speed;
if (object.y >= 595){
object.destroy()
}
}
constructor(scene: Phaser.Scene, x: number, y: number, target: Phaser.Physics.Arcade.Sprite )
{
super(scene, x, y, 'gob')
this.target = target
scene.add.existing(this)
scene.physics.add.existing(this)
this.setScale(2)
this.play("gobRun")
const body = this.body as Phaser.Physics.Arcade.Body
body.setSize(this.width*0.45, this.height*0.7)
body.setOffset(9, 6)
body.setBounce(1,1)
}
preUpdate(time, delta)
{
super.preUpdate(time, delta)
if(this.y < 300)
{
this.moveItems(this, 2.5)
}else if(this.y > 300 && this.y < 550)
{
this.moveItems(this, 4)
this.play("gobBlitz")
}else if(this.y > 550 && this.y < 589)
{
this.moveItems(this, 2)
this.play("gobBack")
}else
{
this.play("gobRun")
this.moveItems(this, 2)
}
if(this.x > this.target.x + 3 && this.y < this.target.y && this.y > 0){
//this.setRotation(-63);
this.x -= 2;
}
if(this.x < this.target.x - 3 && this.y < this.target.y && this.y > 0){
//this.setRotation(63);
this.x += 2;
}
}
}
Hello Mates
I have a sprite, member of a group for which i just cant make rolling the animations…
I use the pre update with super pre update …
This technic had worked for the player sprite but not for the ennemies…
Someone knows why?
Thx for your time and advices!