Game Development Reference
In-Depth Information
_qnnajp@n]cK^fa_p*]``ArajpHeopajan$IkqoaArajp*IKQOA[QL( ±
kjIkqoaQl%7
y
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
y
y
Much of this code is quite familiar to you by now, but there are a few new things here that require
some explanation.
The class uses a Boolean variable called [eo@n]ccejc to keep track of whether you are dragging any
objects. You need this variable to prevent the squares from snapping to their targets before the mouse
button is actually released.
At the heart of the program, however, are the kjIkqoa@ksj and kjIkqoaQl events. This program again
illustrates how two or more objects can share the same event handler. When the program is initialized,
both the na`Omq]na and ^hqaOmq]na objects add the very same kjIkqoa@ksj event listener:
na`Omq]na*]``ArajpHeopajan$IkqoaArajp*IKQOA[@KSJ(kjIkqoa@ksj%7
^hqaOmq]na*]``ArajpHeopajan$IkqoaArajp*IKQOA[@KSJ(kjIkqoa@ksj%7
When the mouse button is pressed down over either of these objects, the kjIkqoa@ksj event handler
is called:
lner]pabqj_pekjkjIkqoa@ksj$arajp6Arajp%6rke`
w
r]n_qnnajp@n]cK^fa_p6Ikrea?hel9arajp*_qnnajpP]ncap]oIkrea?hel7
_qnnajp@n]cK^fa_p*op]np@n]c$%7
oap?deh`Ej`at$_qnnajp@n]cK^fa_p(jqi?deh`naj)-%7
[eo@n]ccejc9pnqa7
_qnnajp@n]cK^fa_p*]``ArajpHeopajan$IkqoaArajp*IKQOA[QL(kjIkqoaQl%7
y
 
Search Nedrilad ::




Custom Search