我想制作一个可拖动的菜单,例如 instragram 和其他应用程序不明白它是纯数学并且应该工作,我试图调整任何值但没有成功任何建议为什么它不工作?谢谢你
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.utils.Timer;
import flash.geom.Point;
/**
* ...
* @author
*/
public class GravityCoinsMain extends Sprite
{
private var theCoin:Coin;
private var deltaX:Number = 0;
private var prevX:Number = 0;
private var newX:Number = 0;
private var PCControl:Boolean = true;
private var speedLimit:Number = 15;
private var timer:Timer = new Timer(10);
private var dragFactor:Number = 0.97;
private function update(te:TimerEvent):void
{
if (PCControl)
{
if (theCoin.x > 0 && (theCoin.x < stage.stageWidth))
{
theCoin.x += deltaX;
deltaX *= dragFactor;
}
}
else
{
prevX = newX;
newX = theCoin.x;
deltaX = newX - prevX;
var speed:Number = deltaX ;
if ( speed > speedLimit )
{
deltaX *= speedLimit / speed;
}
}
}
private function beginDrag(me:MouseEvent):void
{
theCoin.startDrag(false, new Rectangle(0,theCoin.y,5000,0));
PCControl = false;
timer.start();
}
private function endDrag(me:MouseEvent):void
{
theCoin.stopDrag();
PCControl = true;
}
public function GravityCoinsMain()
{
theCoin = new Coin();
addChild(theCoin);
theCoin.x = stage.stageWidth / 2;
theCoin.y = stage.stageHeight / 2;
theCoin.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
theCoin.addEventListener(MouseEvent.MOUSE_UP, endDrag);
timer.addEventListener(TimerEvent.TIMER, update);
}
}
}