HTML and CSS Reference
In-Depth Information
This functionality also makes it easy to use the type of an object where necessary. Notice that bob and jill
respond as expected to the instanceof operator.
Supporting Events
Adding support for events in a game engine makes it easier to keep different parts of the engine from becoming
too tightly coupled. It means one part of the game can communicate events and actions to other parts of the
game without needing to know anything about the objects it's communicating with.
When you add components into the mix, it even allows a sprite to communicate with itself without needing
to know all the components that make it up. A Physics component on a sprite might trigger a collision event,
and two components listening for the event could separately handle triggering the appropriate sound effect and
animation effect.
Designing the Event API
Quintus uses a base class called Evented that is the jumping-off point for any object that needs to subscribe
to and trigger events. As usual, you must think about the API first and then build the code around that API af-
Given a player sprite and a scene object, now walk through an example event functionality:
// Play the intro animation on the player
// when the scene starts
scene.bind('start',player,function() {
// Bind a method on player using the method name
// Trigger the start event on the scene
// Unbind the player from the start event
// Release the player from listening
// to all events (such as if it's blown up)
This API provides a way to bind, trigger, and unbind events as well as release an object from any events
(such as when it is removed from the game) so that sprites that have been destroyed don't continue to respond
to events.
Search WWH ::

Custom Search