Game Development Reference
In-Depth Information
5. Give the new FLA file the name characterControl.fla .
6. Find the ?d]n]_pan?kjpnkh project folder that you created in step 1.
7. Click the Save button.
8. In the Project panel, click the drop-down menu. Select Quick Project . The characterControl.fla file
will appear as a project file.
9. In the Project panel, click the New File button.
10. Enter Main_Character.as in the File field. In this project, you'll start giving the Main classes
unique names. With a lot of projects using the same class names, you might become confused
by which Main belongs to which project. But it's not just you; sometimes the Project panel isn't
sure which Main you're trying to access, either, and sometimes loads the wrong one. When you
see Main as part of a class or file name, you'll know that it refers to the project's document
class.
11. Select ActionScript from the File type drop-down menu and click the Create File button.
12. Flash will create and open the I]ej[?d]n]_pan*]o file.
13. Double-click the jqi^anCqaooejcC]ia*bh] file to make it visible again in the workspace.
14. In the Properties panel, enter Main_Character in the Class field.
15. Save the jqi^anCqaooejcC]ia*bh] file.
And now you're ready to play!
Controlling a player character with the keyboard
One of the most basic requirements of many games is being able to control a player character with
a keyboard. It's not hard to do: it's a technique that makes use of two of AS3.0's built-in classes: the
Gau^k]n`Arajp class and the Gau^k]n` class. To use them, you can simply import them into the top of
your program, along with your other imported classes:
eilknpbh]od*arajpo*Gau^k]n`Arajp7
eilknpbh]od*qe*Gau^k]n`7
Like the IkqoaArajp class that you used in earlier chapters, the Gau^k]n`Arajp and Gau^k]n` classes
contain methods and properties that you can use to help your players interact with your games using
the keyboard. And, like the IkqoaArajp class properties, you'll be using all these new methods and
properties with your eyes closed in no time at all.
Controlling with the keyboard—the wrong way!
There are two ways to control an object with the keyboard: the right way and the wrong way. You'll
actually begin by learning to do it the wrong way first.
Why would you learn the wrong way? Well, the nice thing about doing player keyboard control incor-
rectly is that it's very straightforward and easy to understand. And, oh yeah, it kind of works, too. But
even if you never use it to control a player character in one of your games, you'll find endless other uses
for it as a general technique for figuring out which keys your players are pressing on the keyboard. It's
 
Search Nedrilad ::




Custom Search