我目前正在为一个钓鱼游戏的闪光灯功率计工作,其中用户的鼠标输入决定了一个仪表的垂直功率,有一个容器矩形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;
}
发布于 2011-08-02 17:56:50
如果将用户必须移动鼠标来填充功率计的像素数限制在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.
发布于 2011-08-02 17:54:35
那_diff = value/10;
呢?
目前我不能给你更好的建议,因为我不能完全确定你的代码是做什么的。例如:在哪里调用loop
?
https://stackoverflow.com/questions/6909913
复制相似问题