Jump to content

How to kill a custom sprite


Sleider
 Share

Recommended Posts

Hi everyone!

This is my first time coding a game and I have a problem that is killing me.

I have a custom sprite, a eagle, the code below:

eagle = function(game, y) {
    this.damage = randomValue(20,35)
    this.speed = randomValue(3500,5000)
    this.id = randomValue(0,10000)
    posicion = function(){
        return {x:randomDir(), y: randomValue(y-450, y-700)}
    }
    this.coords = posicion()
    Phaser.Sprite.call(this, game, this.coords.x, this.coords.y, 'aguila');
    game.physics.arcade.enable(this);
    this.scale.set(0.15)
    this.body.setSize(225, 150, 20, 50);
    this.body.collideWorldBounds = false

    if (this.coords.x < 0){
        dir = randomValue(500, 1000)
    } else {dir= -1000}  
    

    this.yTween = game.add.tween(this).to({
        y: this.coords.y + 1000
    },this.speed, Phaser.Easing.Bounce.In, true);
    this.xTween = game.add.tween(this).to({x: dir}, this.speed,Phaser.Easing.Bounce.In, true);

    this.xTween.onComplete.add(function () {
       // HERE I WANT TO KILL THE SPRITE
    })
}
eagle.prototype = Object.create(Phaser.Sprite.prototype);
eagle.prototype.constructor = eagle;

So my idea was to spawn the eagle and after the xtween finishes kill this eagle. I've tried many ways to do it:

this.kill() not working

this.alive = false neither

I've tried to create a function and parse the object to kill it but isn't working.  Also I've tried to kill the object by parsing the ID and the group and killing the eagle with the same id but doesn't work too.

I don't know what else I can do :S

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...