Game Development Reference
In-Depth Information
Here are a couple of things to note:
For Flex Builder, Flash Builder, or other IDEs, please refer to the documentation provided for that
product to create a new project and set the default compile class.
A common method of Flash development is to use the Flash IDE for assets and organization and
Flash Develop for code editing. If this is your workflow of choice, you will want to follow the Flash
IDE folder and package structure rather than the Flex SDK folder structure.
Creating game timers
There are two basic methods that most Flash developers implement when creating a frame-
based game timer. By “frame-based,” we mean a timer that uses the idea of a segment of time
broken up into logical slices (or frames) to manage game logic. There are other types of methods
for timing game updates, but we will make extensive use of time-slice or frame-based timers in
this topic. The basic game timer we will use most of the games will attempt to squeeze all
processing and screen updates into each segment or frame. We will also explore a time-step
timer and a sleep-based timer in chapter 11.
The first timer method is the Event.ENTER_FRAME event timer. The standard Event.ENTER_FRAME
event handler will attempt to run the game loop at the .swf file's set frame rate. This very handy
game loop timer has been in use for a number of years. The second standard game loop timer
method makes use of the Timer class. The Timer class is used to call the game loop at
millisecond intervals specified by a delay interval. For example, if the millisecond delay interval is
set to 100 , the Timer instance would run ten times a second (there are 1,000 milliseconds in a
single second). Our framework will begin by using this Timer instance game loop timer. We will do
this so we can make use of the TimerEvent.TIMER updateAfterEvent function. As you will see,
this function will help smooth out screen updates.
Defining “frame timer tick”
You will see the phrases “frame timer tick,” “timer tick,” and “frame tick” used in this topic. When
we refer to a “tick” or a “frame tick,” we simply mean one frame's worth of processing. When we
run a game at 30 frames per second, we have 30 ticks or 30 frame ticks. This also means that we
only have 33.33 milliseconds (or 1,000/30) inside each tick to do all of our processing.
State Machines
A traditional state machine at its very basic is a mechanism that controls the state, or current
actions a system can perform. Sometimes this is called a finite state machine. Finite state
machines have traditionally been used to model complex mathematical computations and more
recently artificial intelligence. The “finite” in the name refers to the fact that the system can only
be in a single state at any one time. Our game framework is built on a simple state machine
pattern that employs a separate code function or method for each state. There are many other
styles of state machines; some use entire classes for each individual state (sometimes called an
object-oriented state machine) and some use a simple switch:case statement block called on
each frame tick to control state. We will use a third type that borrows from these two.
We call our state machine pattern a function reference pattern. Unlike the object-oriented state
machine, our machine will contain a separate method or function for each state inside a single
Search WWH ::




Custom Search