Closed dgpt closed 10 years ago
Check this out; it's awesome.
P.S. here's how it works
Local event in an object: this.addListener('name', callback, oneShot); this.removeListener('name') or this.removeListener('name', listener); (if no listener passed, all events are removed) this.triggerEvent('name');
Global events: events.global.addListener(), events.global.removeListener(), events.global.triggerEvent()
I think you should keep some of the old names though. emit
is much smaller than triggerEvent
. And still is descriptive enough if used like this events.emit
. But verbosity isn't much of an issue, so whatever.
The reason I changed it is because now they are on the object instead of on events.
So, say you wanted to trigger an event on a bullet during Bubble's onBulletCollision:
onBulletCollision: function(bullet) {
...
bullet.triggerEvent('poop');
...
}
Also, since all BasicObjects and States inherit events.EventHandler, the function names 'remove', and 'emit' are off limits because particles and states. It's also a good idea to be more verbose when it's related to inheritance (moment of clarity: that's why Java is so verbose).
Create local/global events
Current plan: Create a class that any event-listenable objects are derived from. An instance of this class is accessed by the events module for the global events.