kurhlaa Posted August 30, 2018 Share Posted August 30, 2018 Hello, I'm trying to understand how some parts of Phaser work. But I'm confused by the emit functions. For example arcade/world.js script at https://github.com/photonstorm/phaser/blob/master/src/physics/arcade/World.js contains: ... this.emit('overlap', body1.gameObject, body2.gameObject, body1, body2); ... this.emit('collide', body1.gameObject, body2.gameObject, body1, body2); ... sprite.emit('overlap', body.gameObject, tile, body, null); ... sprite.emit('collide', body.gameObject, tile, body, null); ... the same in many other places in Phaser. Please explain how to find the exact JavaScript code that is executed by these emit(). Thanks! Link to comment Share on other sites More sharing options...
iKest Posted August 30, 2018 Share Posted August 30, 2018 emit is analog of dispatch signal for EventEmitter3 Link to comment Share on other sites More sharing options...
samme Posted August 30, 2018 Share Posted August 30, 2018 EventEmitter#emit Link to comment Share on other sites More sharing options...
kurhlaa Posted August 30, 2018 Author Share Posted August 30, 2018 So far I understand, that it's possible to do something like that: // Setup listener a.on('overlap', func, this); // Run related function when needed a.emit('overlap', param1, param2); // Function to be executed after calling 'emit' function func(param1, param2) { // ... } is this correct? If Yes - in Phaser there must be somewhere: world.on('overlap', .... sprite.on('overlap', .... but I don't see something like that. Even if I search in Phaser for a string 'overlap' - nothing is there except emit functions Link to comment Share on other sites More sharing options...
samme Posted August 31, 2018 Share Posted August 31, 2018 Phaser doesn't use the collide/overlap events itself, they're for you to use. Link to comment Share on other sites More sharing options...
kurhlaa Posted August 31, 2018 Author Share Posted August 31, 2018 Oh, not everything is being used by Phaser internally, got it, thanks! But in general, if I see object.emit('eventName' ... ) - I should search for object.on('eventName' ... ) and check the function inside, correct? Can I be sure that event's name won't be obfuscated or replaced by variable, so searching for 'eventName' will always give results if such listener exists? Link to comment Share on other sites More sharing options...
Recommended Posts