当所述文本标签具有值时,我的一个文本项目(游戏的得分计数器)不遵循我设置的格式,0
但是一旦它更新到1
或更高,文本的格式就会正确。当分数为0
时,文本为黑色并采用 Times New Roman 字体,但在更新为1
或更高时会更改颜色、字体和字体大小。有问题的项目是scoreText.text
. 这是与scoreText
标签相关的代码片段:
public class Main extends MovieClip {
static var scoreText:TextField = new TextField();
public var scoreFormat = new TextFormat("Arial Rounded MT Bold", 20, 0xFFFFFF);
public function Main()
{
addChild(gameLayer);
addChild(backgroundLayer);
addChild(interfaceLayer);
interfaceLayer.addChild(mainMenu);
soundControl = intro.play(0, 100);
mainMenu.playBtn.addEventListener(MouseEvent.CLICK, startGame);
}
public function startGame(e:Event)
{
scoreText = new TextField();
scoreText.text = String(0);
interfaceLayer.addChild(scoreText);
scoreText.x = 75;
scoreText.y = 0;
scoreText.selectable = false;
scoreText.setTextFormat(scoreFormat);
resetScore();
}
static function updateScore(points)
{
score += points;
scoreText.text = String(score);
var scoreFormat = new TextFormat("Arial Rounded MT Bold", 20, 0xFFFFFF);
scoreHeader.setTextFormat(scoreFormat);
scoreText.setTextFormat(scoreFormat);
}
static function resetScore()
{
score = 0;
scoreText.text = String(score);
}
如果有人可以帮助查明我哪里出错了,我将不胜感激。
谢谢