Sleider Posted May 17, 2017 Share Posted May 17, 2017 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 More sharing options...
Sleider Posted May 18, 2017 Author Share Posted May 18, 2017 I'm thinking in add the sprite to an array inside the onComplete function, then in the update function I want to check that array and kill every srpite that gets in. Is this a good way to do it or should I think in other way? Link to comment Share on other sites More sharing options...
Sleider Posted May 18, 2017 Author Share Posted May 18, 2017 Please I really need help. Any ideas? Link to comment Share on other sites More sharing options...
Recommended Posts