Preparing the field

Create a new file (File | New) then from New Document window select Actionscript 3.0. Set its properties as width to 640 px, height to 480 px, background color to #FFFFFF (white), and frame rate to 6. Also define the Document Class as Main and save the file as snake.fla. I want you to note the low frame rate, set to six. This is because we'll update snake position at every frame, without smooth animations, as it's not required in these kind of games. Anyway, you can make the game run at any number of frames per second, having a variable, with a counter, that runs the update function and resets itself at every n frames. We'll discuss this at the end of the chapter.

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.