Game Development Reference
In-Depth Information
14. Click the down button and then the up button. The cat should now be able to move up and
down the hill, as shown in Figure 4-4.
Figure 4-4. Click the buttons to move the cat up and down the hill.
That's amazing, isn't it? Funny how such a simple little effect can be so satisfying to watch, especially
after all the effort you've put into the storybook so far.
You should recognize much of the new code from Chapter 2. You've simply added event listeners to
the two new buttons and created event handlers to run the appropriate directives. However, there is
one new line of code that might stand out:
Previously, that line read ]``?deh`$op]npL]ca%7. Why was it changed? In this part of the chapter
you'll be working with the hill page. It would have been a big bother if every time you tested the
program you needed to first click the hill button on the start page to get there. For testing purposes, it
makes sense to display the hill page right away. Later, when the program is finished and you're happy
with the way everything is working, you can change it back to the way it was.
Let's have a look at the directive in the kj@ksj>qppkj?he_g event handler:
The object name of the cat is dehhL]ca*_]p. The _]p object is an instance inside the dehhL]ca object,
so you need to write out its full name using dot notation. The u stands for the u property of the object.
The u property represents its vertical position, in pixels, from the top of the stage. The equal sign is
used to assign it a value of ..,. (The value you use might be different.) The original position of the cat
is -.,, so when you click the button, the event handler moves the cat to the new position, creating the
illusion that it has moved down the hill.
Search Nedrilad ::

Custom Search