Programming the Game with JavaScript
As mentioned in the previous section, Preparing the Game Timeline, Stage, and Library, since we are targeting the native web with an HTML5 Canvas document, we'll be programming our game with JavaScript. Most code in Animate is bound directly to specific keyframes and is executed when the playhead reaches that frame.
The code we will write is composed of variables and functions. When we want to hold data or change data, we use variables. The first time a variable is declared, we use the keyword var
. When we need to group a set of instructions together to perform a task, we group them all within a function and then invoke that function when we want to execute the code.
As we start building the code for our game, recall that certain objects exist on the stage already and have been given instance names to allow us to manipulate them. In addition to this, there is a set of objects that only exist within the library and have been given linkage...