Thursday, February 5, 2009

Part 1 - Movement/User Input

Flash Game Tutorials

Part 1 - Movement/User Input

This tutorial will teach you how to create a character controlled by the user. It can be whatever you want it to be. I was creative and made a grey ball.





2. Select it and hit F8 to make it a symbol.

3. Select movieclip.

note: you must choose movieclip, so you can control it with actionscript code.





4. Click the middle box for its registration.

note: registration tells the computer where the ball is on screen, if you selected left, the computer would think the center of the ball was at the ball's left edge





5. Name it whatever you want, then hit OK.

note: the name you picked is what the symbol is called in the library, it doesn't affect your code.

6. You must give the ball an instance name. This is the name you will use to access the ball in your code. Instance name your symbol ball.

note: to instance name a symbol click on it and use the symbol's properties window





7. Now for the code. Click on the keyframe in the timeline, then hit F9 to bring up the actions(code) panel.

note: F9 is the default hotkey to open/close the actions panel; you may also find it by clicking Window, then, Actions in the menu at the top of the screen.





8. Type the following code in the actions panel. It isn't selectable because you should retype it to help you learn.



(line by line explanation below)

Line: Actionscript


Line 1: sets the variable “speed” equal to 8

Line 3: everything inside this function will run over and over again.

Note: this runs at the speed of the framerate, so if the framerate is 24 frames per second, this code will run 24 times per second

Line 5: this is an if statement if the key is pressed down, then the code inside the brackets will run, otherwise it does nothing

Note: 37 is the ascii code for the Left Arrow. An ascii code table can be found at http://www.asciitable.com/