Game Development Reference
In-Depth Information
label.autoSize;
label.defaultTextFormat = labelTextFormat;
label.text = labelText;
content.autoSize;
content.defaultTextFormat = contentTextFormat;
content.text = contentText;
label.x = 0;
content.x = labelWidth + bufferWidth;
addChild(label);
addChild(content);
}
public function setLabelText(str:String):void {
label.text = str;
}
public function setContentText(str:String):void {
content.text = str;
}
}
}
What exactly is a score board element? The player's score, for example, is something that we
want to display to the user. So, we have a label of
Score
followed by the actual score value. On
the screen it would look something like this:
Score 85
0.
There is nothing spectacular here really, but it's adequate for the simple display needed in this
topic.
The variable definition section for this class is very simple. We need to define variables to hold
the
label
and
content
values as well as the buffer value for the number of pixels to separate
these two text elements.
This class extends
Sprite
and contains two text fields, separated by a buffer set of pixels defined
by the
bufferWidth
variable. The
label
variable holds the text that represents the left-side static
label for the display. The
content
variable represents the content to the right of the
label
. So, for
the previous example, the word Score is the label and the value 8500 is the content.
The constructor definition
The constructor does most of the heavy lifting in this class. Here are definitions of the passed-in
parameters:
x
is the
x
axis screen location for the starting point to draw the
label
and the
content
on
the
ScoreBoard
.
y
is the
y
axis screen location for the starting point to draw the
label
and the
content
on
the
ScoreBoard
.
bufferWidth
is the buffer space, in pixels, between the
label
and the
content
.
labelText
is the
String
of text for the
label
.