Game Development Reference
In-Depth Information
The elements needed in a call to the
createTextElement
function follow:
A
String
representing the key for the element, which is very much like the
id
in the
BasicScreenClass
and will be used to determine what element to update
An instance of the
SideBySideScoreElement
class
There are eight elements needed to create an instance of the
SideBySideScoreElement
class. The
class creates an instance of
Sprite
with a field for a static label and a field for changeable
content text. The
SideBySideScoreElement
class will be discussed in detail in the next section. For
now, you just need to understand that it creates a visual screen element on the
ScoreBoard
that
shows a
String
label
and then a
String content
next to the
label
. They are separated by a
buffer
space. For instance, we need a
SideBySideScoreElement
instance for the score. The label
will be the word Score and the content will be the player's score.
The
x
location for the
Sprite
holding the label and the text
The
y
location for the
Sprite
holding the label and the text
The buffer space, in pixels, between the label and the text
The
String
of text for the label, for example Score
The
TextFormat
of the label
The
width
in pixels for the label
The initialization text for the context text, for example, 0 for a new game's beginning score
The
TextFormat
for the content
The createTextElement function definition
The
createTextElement
function stores the passed key value into the associative array and the
newly created instance of the
SideBySideScoreElement
as the value of the key/value pair. These
will be used in the update function that is called by
Main
to update score elements.
public function createTextElement(key:String,
obj:SideBySideScoreElement):void {
textElements[key] = obj;
addChild(obj);
}
The update function definition
The
update
function is a public function that allows the updating of a
SideBySideScoreElement
instance on the
ScoreBoard
. In the framework, the
Main
class calls this function after receiving
events from the
Game
class instance.
//update() is called by Main after receiving a custom event
//from the Game class
tempElement.setContentText(value);
When we get to th we will see a
CustomEventSCoreBoardUpdate
that fires off when the score
needs to be updated: