Jump to content

How can I use addListener to respond to an event?


Recommended Posts

I would like to fire a method eavery time my pc sprite rebounds off the edges of the screen. I know I can set a physics body to emit an event:

this.hero.body.setCollideWorldBounds(true); // Hero collides with the bounds of the screen
this.hero.body.onWorldBounds = true; // Emit 'worldbounds' when hero collides with the edge of the screen.

(I've gathered this from here: https://github.com/photonstorm/phaser/blob/v3.11.0/src/physics/arcade/Body.js#L922)

But I don't know how to implement the listener. I have tried:

this.hero.addListener('worldbounds', this.respondToEvent);

        console.log('Testing. Hello!');

...but nothing fires. According to the documents `addListener` is supposed to be here: https://github.com/photonstorm/phaser/blob/v3.11.0/src/events/EventEmitter.js#L111 but all I see is documentation stuff. Am I right to assume it is yet to be implemented?

If it has been implemented, how to I go about responding to the `worldbounds` event?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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