Game Development Reference
In-Depth Information
public static const STATE_SYSTEM_PRELOAD:int = 11;
public static const STATE_SYSTEM_MOCHI_HIGHSCORES:int = 12;
public static const STATE_SYSTEM_PAUSE:int = 99;
Adding new variables for the preloader state
Now, we need to add support in
com.efg.framework.GameFrameWork.as
file for the Flash IDE
preloader. You need to add in a
Boolean
(
preloaderStarted)
and a
String
(
preloadString
).
These will be used inside the preloader state function to control preloading status and display text
to the user.
public var preloaderStarted:Boolean=false;
public var preloadString:String=new String();
Defining the preloadScreen instance
The preload screen will be an instance of the
BasicScreen
class. We will create an instance of the
screen when we discuss the Tunnel Panic game later in this chapter. Add this line to the
com.efg.framework.GameFrameWork.as
file's variable definition section.
public var preloadScreen:BasicScreen;
Setting the preloader to be the first state in Main
At some point, you will want to display the preloader. It is necessary to always use the preloading
state even if you are using another preloader (such as the Mochi Ads preloader discussed in the
next section). You must do this to ensure all of the library assets will be available to your code
when needed.
If
STATE_SYSTEM_PRELOAD
is the only preloader in your game (that is, if you are not using a
Mochiad or other preloaded ad), you will need to set the first game state to be this state. This is
done in the
init
function of the
Main.as
class. Again, you will see this in use shortly when we
discuss Tunnel Panic. For now, you need not make any changes to
GameFrameWork.as
for this,
but here's the how we will set the preloader state for reference:
switchSystemState(FrameWorkStates.STATE_SYSTEM_PRELOAD);
Adding to the switchSystemState function
We do need to make changes to the
switchSystemState
function in
GameFrameWork.as
to support
preloading. It must be modified to include a way to change the state machine to the
FrameWorkStates.STATE_SYSTEM_PRELOAD
state. Add the following code to the
switch
statement in
the
switchSystemState
function:
//*** add these lines
case FrameWorkStates.STATE_SYSTEM_PRELOAD:
systemFunction = systemPreload;
break;
//*** end add these lines