AS3看到每一个得分

时间:2012-03-20 04:31:44

标签: actionscript-3

我最近接受了编程,在分数显示方面遇到了问题。分数没有增加问题并且显示它只是因为分数更新它不会删除最后分数。在十几帧后,我显示了混乱的分数。我花了几天谷歌搜索,看看我是否能找到任何类型的答案,但没有看到类似的问题。

我的代码:

public function  balldistance(event:Event){ // function called on ENTER_FRAME in order     to update the distance of the ball object

var txt:TextField = new TextField(); 
txt.text = "Distance:  " + String(balldist);
txt.x = 25;
txt.y = 25;
addChild(txt);

trace(balldist);  // I added this line in my code for troubleshooting purposes just so    I could see the balldist augment.
balldist += Ball5.dx;  // I am having the score(balldist) augment based on the distance the ball has traveled from its starting point.
}

我的一个朋友建议使用removeChild(txt),但是当我尝试这个时,它没有显示分数更新。

谢谢

1 个答案:

答案 0 :(得分:0)

看起来你正在创建一个新的txt:TextField每次触发ENTER_FRAME。

尝试在该侦听器函数之外声明/初始化一次:

var txt:TextField = new TextField(); 
txt.x = 25;
txt.y = 25;
addChild(txt);

然后输入框参考SAME txt TextFeild实例,而不是一遍又一遍地创建一个新实例:

public function  balldistance(event:Event){
  txt.text = "Distance:  " + String(balldist);
  balldist += Ball5.dx;
}