Game Development Reference
In-Depth Information
This listener figures out which keys are being released and sends this information to the kjGauQl event
handler so that you can do something useful with it. But why would you want to know whether a key
is no longer being pressed? Think about it this way: you changed the kjGau@ksj event handler so
that when the player of the game presses one of the arrow keys, the velocity of the lh]uan object is
changed by 5 pixels. That's great because when you press one of the arrow keys, you obviously want
the lh]uan object to move. But what about when you stop pressing one of the arrow keys? It would
make sense if the lh]uan object also stopped. However, unless you specifically tell the program this,
it doesn't know what you intend, and the lh]uan object just continues moving endlessly, forever. This
wasn't a problem in the simple keyboard control program in which the kjGau@ksj method was chang-
ing the lh]uan object's t and u properties directly, but now that you're using velocities and delegating
the task of actual movement to the kjAjpanBn]ia event handler, it becomes a big problem.
The job of the kjGauQl event handler is to check whether any of the arrow keys is released and then
set the lh]uan object's velocity to ,. That's what this code does:
bqj_pekjkjGauQl$arajp6Gau^k]n`Arajp%6rke`
w
eb$arajp*gau?k`a99Gau^k]n`*HABPxx ±
arajp*gau?k`a99Gau^k]n`*NECDP%
w
rt9,7
y
ahoaeb$arajp*gau?k`a99Gau^k]n`*@KSJxx ±
arajp*gau?k`a99Gau^k]n`*QL%
w
ru9,7
y
y
It should be pretty self explanatory, but there's one thing that will be new to you: the kn operator. It
looks like this:
xx
It's made up of two pipe characters . The pipe character is a vertical line, and you'll find it somewhere
on your keyboard near the brace or forward slash keys. Take a good look; it's there somewhere!
The kn operator is used inside conditional statements to help you find out whether one thing or
another thing is true.
Have a look at this line of code:
eb$arajp*gau?k`a99Gau^k]n`*HABPxx ±
arajp*gau?k`a99Gau^k]n`*NECDP%
It literally means this:
Ebpdahabp]nnksgaueo^aejclnaooa`(knpdanecdp]nnksgaueo
^aejclnaooa`(`kpdabkhhksejc*
 
Search Nedrilad ::




Custom Search