2014-03-12 25 views
0
static private function timer():Void 
{ 

    nTimer = nTimer; 
    _root.hud.timer.text = nTimer; 
    nTimer = nTimer - 0.02; 
    if (nTimer == 0) 
    { 
     nTimer = 0; 
     _root.hud.timer.text = nTimer; 
    } 
} 

这是计时器。每次玩家击中敌人时,它都会更新分数并转到使用计时器中的号码并更新分数的此功能。Flash动作脚本2,取整至小数点后两位

static private function updateScore():Void 
{ 
    var num:Number = nScore; 
    num *= 100; 
    num = Math.round(num) 
    num /= 100; 
    nScore = nScore + nTimer; 
    _root.hud.score.text = nScore; 
} 

的问题是,我就不说了比分显示24.23,我想它,它显示一个整数,24

回答

1

很抱歉,但我没有你已了解的意思:

static private function timer():Void 
{ 

    nTimer = nTimer; 
    // why write nTimer = nTimer?? Is like writing 1=1 

    //_root.hud.timer.text = nTimer; 
    // why write this text area two times? you can write it at the end of the function 
    nTimer = nTimer - 0.02; 
    if (nTimer == 0) 
    { 
     // nTimer = 0; 
     // if we are here it means that nTimer == 0, so why to set it again as =0 ? 

     //_root.hud.timer.text = nTimer; 
     // why write this text area two times? you can write it at the end of the function 
    } 
    _root.hud.timer.text = nTimer; 
} 

现在为updateScore函数,你需要什么? 您的脚本舍入NUM VAR 2位小数,但不再如果你想添加到圆角值nTimer值不使用它 ,你有nScore = num + nTimer;

更换 nScore = nScore + nTimer;虽然如果你需要一个圆形值以2位小数作为最后一个值,您必须在添加nTimer值后将其舍入。

最后,你可以用更短的脚本rould的Num:num = Math.round(num*100)/100;

+0

再次谢谢:) – Moynul