Game Development Reference
In-Depth Information
The
addSounds
function is included here because it is called by
systemPreload
. However, to
actually add sounds to the game, this function needs to be overridden by the
Main
class of the
game. We will demonstrate this in Tunnel Panic.
public function addSounds():void {
//stub only needed in IDE preloading
}
Adding Mochi preloader ads and leader boards
The changes to
com.efg.framework.GameFrameWork.as
to add basic Mochi preloader ads and
leader boards are the same for both Flex SDK and Flash IDE based games. You will need to
have created an account at
www.mochimedia.com
, added a game to your account, and created a
leader board for the game before you can place your own ads and leader boards to your game.
The game and board IDs shown in the next examples are real, live working ads. They work only
for our test account though, and any money earned with those codes will go into that account. So
be sure to
change the game and board IDs
. You have been warned!
The Mochi functionality will add new states in our state machine. If you are using the Flash IDE
and have already read through the section on the preloader code, you will have seen the states
added for the Mochi ads and leader boards. If you have not read that section but are using the
Flash IDE, it is very important that you do so.
Importing the Mochi package
Once you have signed up for a Mochi account, you will be able to download the latest code API
library.zip
file. Inside the file, you will find a folder called
Mochi
. Place this folder inside your
project. If you are using the Flex SDK, it can be inside your
/src
folder. For the Flash IDE, it can
be in the same folder as your FLA. Alternatively, you can add it to the
classes
folder (as we have
done for our code for this topic) or anywhere else, as long as you as you add the reference
directly to the class path of your development tool.
In the class import section of the
com.efg.framework.GameFrameWork.as
and
Main.as
class, add
this line:
import mochi.as3.*;
Changing the Main.as object type
The
Main.as
class that extends
com.efg.framework.GameFrameWork
must be a specific type for it
to work with the Mochi API. It must be a
MovieClip
, not a
Sprite
, and it must be declared
Dynamic
. For your game, change the
Main.as
class construction line to this:
dynamic public class Main extends MovieClip {
We will demonstrate this shortly with the Tunnel Panic game.
Adding Mochi-related variables to the framework
Just like we did with preloading, we need to add some states to
com.efg.framework.
FrameWorkStates.as
to support the Mochi services. These are the lines we need to add to the