I am trying to detect when the sprite reaches the end of the path to destroy it. My code:
var enemy = "Triangle";
this[enemy] = this.add.follower(aPaths[path], -20, 200, enemy).startFollow({
duration: 5000,
loop: 0
});
EDIT: I was posting a new answer and by mistake I edited and overwrote the OP… but it was basically the above.
samme
2
Put onComplete: () => {…}
in the startFollow()
config object. Also callbackScope: this
, probably.
Hey Samme, look what I did:
this[enemy] = this.add.follower(aPaths[path], -20, 200, enemy).startFollow({
duration: 5000,
loop: 0,
onComplete: function(){
this.destroy();
},
callbackScope: this
});
However it’s returning me the error:
Uncaught TypeError: this.destroy is not a function
Any idea?
samme
4
Change to callbackScope: this[enemy]
.
callbackScope
is just the this
value of the callback, so you can use any you want.
It worked (no need to specify the callbackScope if using arrow function since it already sets the scope to this):
this[enemy] = this.add.follower(aPaths[path], -20, 200, enemy).startFollow({
duration: 5000,
loop: 0,
onComplete: () => {
this[enemy].destroy();
},
});
Although it IS needed to set the callbackScope to this if using regular function:
this[enemy] = this.add.follower(aPaths[path], -20, 200, enemy).startFollow({
duration: 5000,
loop: 0,
onComplete: function () {
this[enemy].destroy();
},
callbackScope: this,
});
Both ways will work.