繁体   English   中英

TextFormat最初无法正常工作

[英]TextFormat not working as intended initially

我的一个文本项(游戏的分数计数器)没有遵循我设置的格式,该文本标签的值为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);
}

如果有人可以帮助您确定我哪里出了问题,我将不胜感激。

谢谢

尝试这个

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);
}

尝试为您的TF设置defaultTextFormat ,它将以文本格式保存跳转。

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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM