Game Development Reference
In-Depth Information
public override function clone():Event {
return new CustomEventScoreBoardUpdate(type,element,
value, bubbles,cancelable)
}
}
}
The only real differences in all three of the custom
Event
classes we will create are the constant
values used to create an instance of the event and the data that is passed along with the event:
public static const UPDATE_TEXT:String =
"update scoreboard text";
public var element:String;
public var value:String;
The
element
variable represents a constant value in the
Main.as
(
GameFrameWork.as
child class)
representing the element on the score board to update. The
value
variable is the actual value to
change the element to. Let's jump into a discussion of the
ScoreBoard
framework class now to
help solidify this topic.
The ScoreBoard class
Most likely, the
ScoreBoard
class will be custom for each game you create. Like the
BasicScreen
class, the
ScoreBoard
class in the framework is as very simple and will probably need some
modification or enhancements if you were to use it in a full commercial game. There are some
basic things that all scoreboards will need though, such as events and communication between
itself and the
Game
class instance. The
ScoreBoard
allows the
Main.as
to create and position as
many instances of the
SideBySideScoreElement
framework class (to be discussed next) as
needed. These are set up each with a name value that corresponds to constants set up in the
Main.as
class. Let's take a look at the code for this class now, and you will see the
Main.as
customizations to create elements on the
ScoreBoard
when we get to the final section on creating
the stub game.
Create the
ScoreBoard.as
file in the framework package structure we created earlier:
/source/classes/com/efg/framework/ScoreBoard.as
Here is entire code listing for this class:
package com.efg.framework
{
// Import necessary classes from the flash libraries
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
/**
* ...
* @author Jeff Fulton and Steve Fulton
*/
public class ScoreBoard extends Sprite {
private var textElements:Object;
//Constructor calls init() only