2011-08-02 39 views
0

我目前正在研究一款釣魚遊戲中的功率計,其中用戶鼠標輸入決定了量表的垂直功率,有一個容器矩形MC和一個長度爲1的儀表矩形,根據mouseStart事件和mouseMove事件計算出的差異調整儀表高度,是否有更好的計算方法?因爲目前略有不同會導致電錶中出現大的「跳躍」。功率計量表動畫

杆的功能。

private function touchStarted(evt:MouseEvent):void 
     { 
      startY = evt.stageY; 

     } 
     private function rotateTurret(evt:MouseEvent):void 
     { 
      trace("rot "+rotation); 
      endY = evt.stageY; 

      if (startY != 0) 
      { 
      difference = startY-endY ; 
      txt.text = difference.toString(); 
      _powerMeter.increment(difference); 
      } 
       } 

功率計功能

private function loop(e:Event):void 
    { 


     fill.height += _diff; 

     if (fill.height >= 200) 
      fill.height = 200; 
     if (fill.height < 0) 
      fill.height = 0;   

    } 

    public function increment(value:Number):void 
    { 
     _diff = value; 
    } 

回答

0

如果限制用戶必須移動鼠標以將功率計填充到[0..1]範圍內的像素數,則可以更輕鬆地將功率計與實際的鼠標移動分開。

您可以通過將difference除以所需的總長度作爲完全填充功率計所需的最大像素數。

更新rotateTurret功能可能是這樣的:

if(startY != 0) { 
    var maxPixelsNeeded:Number = 300.0; 

    difference = (startY-endY)/maxPixelsNeeded; 

    // -- same as before 
} 

您還需要改變循環功能,因爲_diff變量現在將在範圍[0..1],以:

fill.height = _diff * 200; // Where 200 is the max height of the power meter. 
0

如何_diff = value/10;

我現在不能給你更好的建議,因爲我不完全確定你的代碼是幹什麼的。例如:loop叫哪裏?

+0

循環在功能類的enterFrame中被調用。 – sutoL