Jump to content

Understanding the 'emit' functions


kurhlaa
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

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