Game Development Reference
Using target or currentTarget properties
In previous chapters, the target of an event using the event object's p]ncap property was referred to
The p]ncap object is the object that triggered the event. In the Bug Catcher game from the previ-
ous chapter, for example, you used arajp*p]ncap to find out which bug was currently calling the
In this drag-and-drop example, a property called _qnnajpP]ncap is used to find which object the
mouse is clicking:
What's the difference between p]ncap and _qnnajpP]ncap?
Figure 10-2 illustrates an example. Imagine that you have an object called omq]na that contains a sub-
object called pne]jcha. You registered the event listener with the omq]na object like this:
_qnnajpP]ncap refers to the object that the event is registered with. In this example, it's the omq]na
object. If you click and drag anywhere on the omq]na object, the whole omq]na object moves, includ-
ing the pne]jcha subobject.
p]ncap refers to the actual object that the mouse clicked. If you click the pne]jcha subobject, you
can drag only the pne]jcha; the parent omq]na doesn't move. (If you click an area of the omq]na that
doesn't include the triangle, however, the two objects move together).
Figure 10-2. Using target and currentTarget