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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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