Hi!
Here we go again…
I think I still didn’t figure the Phaser scope out correctly. I am having a hard time to refer to the callback function itself (for instances to auto-remove the event itself). This is the demo code I have with a timed event:
for (let w=1; w<=4; w++) {
var mintime = 500;
var maxtime = 1000;
var mytime = Math.random()*(maxtime - mintime) + mintime;
var eventname = "event"+w;
this[eventname] = this.time.addEvent ({
delay: mytime,
callback: () => {
console.log(eventname)
},
callbackScope: this // I also tried this[eventname] and not setting scope at all
});
}
The code creates four instances of a time event named from (event1…event4). They are correctly created as if I console.log this it will show the scene with all the four events. However when I try to console.log it from within the callback I get four event4 and not event1…event4 as would be expected.
Any idea?