2014-03-12 5 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; 
    } 
} 

이것은 타이머입니다. 플레이어가 적을 때릴 때마다 점수를 업데이트하고 타이머에서 숫자를 사용하여 점수를 업데이트하는이 기능으로갑니다.플래시 액션 스크립트 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 반올림하지만 반올림 된 값으로 nTimer 값을 추가하려는 경우, 당신은 당신이 둥근 값을 필요로하는 경우 동안 nScore = num + nTimer;

nScore = nScore + nTimer;를 교체해야 더 이상 를 사용하지 않습니다 마지막 값으로 2 자리 소수점을 사용하려면 nTimer 값을 추가 한 후 반올림해야합니다.

끝에

, 당신은 짧은 스크립트의 num을 rould 수 있습니다 num = Math.round(num*100)/100;

+0

이 다시 한번 감사드립니다 :) – Moynul

관련 문제