02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1: Your first game<br />

Adding the bats<br />

At this stage you have an option; you can try yourself <strong>to</strong> create the bat as shown in Figure 1.15 or you<br />

can take the easy way out and open the project on the CD ‘Examples/Chapter01/Pingpong03.fla’.<br />

Each bat uses the same symbol, with the left bat flipped horizontally by using<br />

‘Modify/Transform/Flip Horizontal’ <strong>to</strong> create the right bat.<br />

Figure 1.14 Selecting Edit Symbols Figure 1.15 The bat<br />

Adding a little code<br />

Now is the time <strong>to</strong> start <strong>to</strong> enter a little <strong>ActionScript</strong>. Click on the right-hand bat <strong>to</strong> select it, and<br />

then open the Actions panel either by selecting ‘Window/Development Panels/Actions’, or by<br />

pressing F9, or by clicking on the blue arrow icon at the right of the Properties panel. You should<br />

see something similar <strong>to</strong> Figure 1.16 on page 8.<br />

Fear not if the sight of all this gibberish fills you with dread, we will examine this code a bit at<br />

a time. Firstly, the opening line:<br />

onClipEvent(enterFrame){<br />

What does this mean? Remember that we created a symbol, and we chose <strong>to</strong> make this symbol<br />

a ‘Movie Clip’. Movie clips can have code attached <strong>to</strong> them and one of the ways you can add<br />

this code is by clicking on the symbol, selecting actions then adding an ‘onClipEvent’. The curly<br />

brackets { and } contain a section of code, in this case they contain all the code that occurs for<br />

the ‘onClipEvent’. An ‘onClipEvent’ can be passed a little information in the form of a parameter.<br />

The syntax for <strong>Flash</strong> is very similar <strong>to</strong> the syntax for JavaScript, which is often used by pages that<br />

you will view in an Internet browser. A parameter is contained within regular brackets, ( and ).<br />

In this example the parameter passed is ‘enterFrame’; this occurs as the timer flips on <strong>to</strong> the next<br />

time segment. If you set the movie frame rate <strong>to</strong> 20, then this section of code will run 20 times<br />

a second. If this sounds a lot, bear in mind that many commercial games aim for frame rates of<br />

50 times a second or above. The higher the frame rate the smoother an animation will appear;<br />

however, the computer hardware must be able <strong>to</strong> sustain this level of computation. For now we<br />

7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!