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 17: Platformers<br />

array, ‘dynamicClips’, so that at a later stage you will be able <strong>to</strong> remove it. In order <strong>to</strong> add a new<br />

element <strong>to</strong> an array, simply use ‘push’.<br />

dynamicClips.push(newclip); //newclip is the name that will be s<strong>to</strong>red<br />

Suppose that when the cat lands on a certain box you want <strong>to</strong> set off an animation that includes<br />

a fish power-up <strong>to</strong>ken. First you create the graphics and animation and s<strong>to</strong>re this in a clip that is<br />

off-screen. Make sure that the animation in the clip s<strong>to</strong>ps at the end rather than loops back and<br />

have it set a flag at the start, something like ‘clipFinished=false’ which is set <strong>to</strong> true at the end<br />

of the animation. On the main ticking loop for the game, either a clip event or a main timeline<br />

loop, run through every clip in the dynamicClips array. If you find that the variable ‘clipFinished’<br />

is true then remove the clip using:<br />

removeMovieClip(clipname);<br />

then update the array so that it is not removed again. A single element can be removed from<br />

an array using the ‘splice’ method. This method takes the starting index in the array and then<br />

a parameter that defines how many elements <strong>to</strong> delete. The same method can take a third and<br />

subsequent parameters; these subsequent parameters define elements that are added <strong>to</strong> the array.<br />

These parameters are optional and when missing, the method operates just by removing elements<br />

rather than removing and replacing.<br />

If the second parameter is missing then the array is deleted from the number index indicated by<br />

the first parameter up <strong>to</strong> the end of the array.<br />

for (i=0; i

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

Saved successfully!

Ooh no, something went wrong!