Game Development Reference
In-Depth Information
The next time the button is clicked, exactly the same thing happens, except that dehhL]ca*_]p*u now
starts with a value of 135 pixels. Fifteen pixels are added again, so the new value becomes 150. Each
new button click adds another 15 pixels to the position, and the result is that the cat looks like it's
gradually moving down the hill.
Tracing the output
To help you come to grips with how this is working, add a pn]_a directive to the event handlers in the
program:
1. Add the following code in bold to the kjQl>qppkj?he_g and kj@ksj>qppkj?he_g event
handlers:
bqj_pekjkjQl>qppkj?he_g$arajp6IkqoaArajp%6rke`
w
dehhL]ca*_]p*u9dehhL]ca*_]p*u)-17
pn]_a$dehhL]ca*_]p*u%7
y
bqj_pekjkj@ksj>qppkj?he_g$arajp6IkqoaArajp%6rke`
w
dehhL]ca*_]p*u9dehhL]ca*_]p*u'-17
pn]_a$dehhL]ca*_]p*u%7
y
2. Save the I]ej*]o file and test the project.
Click the down button a few times. Each time you click it, you'll see the
new value of the dehhL]ca*_]p*u property displayed in the Output panel.
Although your numbers will be different, the effect will be similar to what
I see in my Output panel, as shown in Figure 4-6. You can see that the values
increase by 15 with each click.
Clicking the up button produces numbers in the opposite direction as the
cat moves up the stage.
Figure 4-6. Trace displays the
value of the cat's y property each
time you click the down button.
Using a pn]_a directive is a great way to help you figure out what your code
is doing, and you'll be using it a lot to help test and debug the projects in
this topic.
 
Search Nedrilad ::




Custom Search