Flash 电能表动画

Flash 电能表动画,flash,actionscript-3,Flash,Actionscript 3,我目前正在为一个钓鱼游戏开发flash中的功率计,其中用户鼠标输入决定了仪表的垂直功率,有一个容器矩形MC和一个由1个高度组成的米矩形,米高度根据mouseStart事件和mouseMove事件计算出的差值进行调整,有没有更好的计算方法?因为目前一个微小的差异将导致一个大跳跃米 杆的功能 private function touchStarted(evt:MouseEvent):void { startY = evt.stageY; }

我目前正在为一个钓鱼游戏开发flash中的功率计,其中用户鼠标输入决定了仪表的垂直功率,有一个容器矩形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;
    }
那么_diff=value/10


我现在不能给你更好的建议,因为我不能完全确定你的代码是做什么的。例如:循环调用在哪里?

如果您将用户移动鼠标填充功率计的像素数限制在[0..1]范围内,则更容易将功率计与实际鼠标移动分开

通过将差值除以所需的总长度,作为完全填充功率计所需的最大像素数

更新后的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.

在enterFrame为power guage类调用循环。