mhcdotcom Posted November 6, 2018 Share Posted November 6, 2018 Hey All, I hope you can help me. I've asked the same question on Stack overflow. I hope you don't mind using it as a reference and answering either here or there. https://stackoverflow.com/questions/53093928/how-can-i-call-a-function-in-a-class-from-a-collider-method-when-this-is-a-diffe You're help is really appreciated. Thank you. Link to comment Share on other sites More sharing options...
elleniaw Posted November 7, 2018 Share Posted November 7, 2018 As you can see in here: https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Factory.html#collider__anchor the method takes a callback, but also as a last parameter it takes a context. So instead of doing this: create(){ this.physics.add.collider( this.player, this.bombs, npcs.hitBomb, null, this ) Do this: create(){ this.physics.add.collider( this.player, this.bombs, npcs.hitBomb, null, npcs ) Because now you pass a context to the callback (npcs.hitBomb) the npc's context. If you ever run into a situation where a method would not give you the possibility to pass a context you can look into .bind: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind Lambdas are also a great way to work around it but I would not recommend that for how you want to use it (calling a method on another object) mhcdotcom 1 Link to comment Share on other sites More sharing options...
samme Posted November 7, 2018 Share Posted November 7, 2018 mhcdotcom 1 Link to comment Share on other sites More sharing options...
Recommended Posts