0

当所述文本标签具有值时,我的一个文本项目(游戏的得分计数器)不遵循我设置的格式,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);
}

如果有人可以帮助查明我哪里出错了,我将不胜感激。

谢谢

4

2 回答 2

0

尝试设置defaultTextFormat您的 TF,它将为您节省文本格式的跳转。

public function startGame(e:Event)
{
    scoreText = new TextField();
    scoreText.defaultTextFormat=new TextFormat("Arial Rounded MT Bold", 20, 0xFFFFFF);
    scoreText.text = String(0);
    interfaceLayer.addChild(scoreText);
    scoreText.x = 75;
    scoreText.y = 0;
    scoreText.selectable = false;
    resetScore();
}
于 2013-05-13T05:33:35.560 回答
0

尝试这个

public class Main extends MovieClip {

static var scoreText:TextField = new TextField();
static 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.setTextFormat(scoreFormat);
    scoreText.text = String(0);
    interfaceLayer.addChild(scoreText);
    scoreText.x = 75;
    scoreText.y = 0;
    scoreText.selectable = false;
    resetScore();
}

static function updateScore(points)
{
    score += points;
    scoreText.text = String(score);
    scoreHeader.setTextFormat(scoreFormat);
}

static function resetScore()
{
    score = 0;
    scoreText.text = String(score);
}
于 2013-05-12T23:21:29.357 回答