Game Development Reference
In-Depth Information
This event handler does a number of interesting things:
It figures out which object has been clicked by accessing the event's arajp*_qnnajpP]ncap prop-
erty and assigning it to a variable called _qnnajp@n]cK^fa_p (more on the _qnnajpP]ncap property
ahead):
r]n_qnnajp@n]cK^fa_p6Ikrea?hel9arajp*_qnnajpP]ncap]oIkrea?hel7
It then invokes the op]np@n]c method of the object. This starts the object dragging, with the
effect you can clearly see on the stage:
_qnnajp@n]cK^fa_p*op]np@n]c$%7
You want the object that you're dragging to be above all the other objects on the stage. This
creates the illusion that it's being picked up. To do this, you need to move it to the highest
position in the display list. oap?deh`Ej`at$_qnnajp@n]cK^fa_p(jqi?deh`naj)-% takes care of
that quite nicely:
oap?deh`Ej`at$_qnnajp@n]cK^fa_p(jqi?deh`naj)-%7
It sets the [eo@n]ccejc variable to pnqa:
[eo@n]ccejc9pnqa7
It adds the kjIkqoaQl listener to the object. You could have easily added this event to the
object in the constructor method, but, for performance reasons it's generally a good idea to
create listeners only when you need them. You don't need to listen for a IKQOA[QL event
before the IKQOA[@KSJ event is triggered, so it makes sense to add it here:
_qnnajp@n]cK^fa_p*]``ArajpHeopajan$IkqoaArajp*IKQOA[QL(kjIkqoaQl%7
Now that you can happily drag the object around the stage, what happens when the mouse is released?
The kjIkqoaQl event handler is called:
lner]pabqj_pekjkjIkqoaQl$arajp6Arajp%6rke`
w
r]n_qnnajp@n]cK^fa_p6Ikrea?hel9arajp*_qnnajpP]ncap]oIkrea?hel7
_qnnajp@n]cK^fa_p*opkl@n]c$%7
[eo@n]ccejc9b]hoa7
_qnnajp@n]cK^fa_p*naikraArajpHeopajan$IkqoaArajp*IKQOA[QL( ±
kjIkqoaQl%7
++@eolh]updaj]iakbk^fa_ppd]pikqoaeonaha]oa`kran
eb$_qnnajp@n]cK^fa_p*`nklP]ncap9jqhh%
w
pn]_a$_qnnajp@n]cK^fa_p*`nklP]ncap*l]najp*j]ia%7
y
y
This event listener uses the target object's opkl@n]c method to stop the drag effect. It sets [eo@n]ccejc
to b]hoa and then removes itself after completing the job.
 
Search Nedrilad ::




Custom Search