Jump to content

group.onDestroy.add - cannot pass arguments[SOLVED]


Igor Georgiev
 Share

Recommended Posts

Hey guys, I got a weird behavior from using the callback method on group.onDestroy:

this.playerCar = 'car1';
this.enemyCar = 'car2';
this.optionsGroup.onDestroy.add(this.currentTrack.createCars, this, 0, this.playerCar, this.enemyCar);

and what I get on the other side instead of 'car1' and 'car2', is: [object, object] and true. I even tried using: this.currentTrack.createCars.bind(this), but it does not help

Does anyone know why?

Phaser version 2.6.2

Edited by Igor Georgiev
Found solution
Link to comment
Share on other sites

13 minutes ago, Igor Georgiev said:

Hey guys, I got a weird behavior from using the callback method on group.onDestroy:


this.playerCar = 'car1';
this.enemyCar = 'car2';
this.optionsGroup.onDestroy.add(this.currentTrack.createCars, this, 0, this.playerCar, this.enemyCar);

and what I get on the other side instead of 'car1' and 'car2', is: [object, object] and true. I even tried using: this.currentTrack.createCars.bind(this), but it does not help

Does anyone know why?

I just had an Idea, does it actually pass one argument with both objects in it as an array? So then on the callback, I have to accept one argument and this argument will be the 2 objects and I just have to extract them?

I also see in the debug, that actually the group is being passed as parameter. Why? What should the context be?

Link to comment
Share on other sites

17 minutes ago, Igor Georgiev said:

I just had an Idea, does it actually pass one argument with both objects in it as an array? So then on the callback, I have to accept one argument and this argument will be the 2 objects and I just have to extract them?

I also see in the debug, that actually the group is being passed as parameter. Why? What should the context be?

Fixed it by using:

this.optionsGroup.onDestroy.add(function () {this.currentTrack.createCars(this.playerCar, this.enemyCar);}, this, 0);

But I believe this should not be the case. Something gets messed up in the add method. Anyway, for future readers - this is the way to go. Or maybe it will be fixed in the next versions :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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