Goshawk Posted July 19, 2018 Share Posted July 19, 2018 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); } 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 More sharing options...
Goshawk Posted July 20, 2018 Author Share Posted July 20, 2018 I see the correct way is: this.physics.world.on('worldbounds', function(){ console.log('Testing. Hello.'); }); Link to comment Share on other sites More sharing options...
Recommended Posts