我拖了mc叫" box"但拖拽并不顺利。
那么我怎样才能通过使用" easy"变种
我试图使用" / ease"任何地方,但不工作。
var topY:int = stage.stageHeight - box.height;
var botY:int = 0;
box.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
box.addEventListener(MouseEvent.MOUSE_UP, onUp);
var constrainY:Rectangle = new Rectangle(box.x, topY ,0, box.y+ (box.height-stage.stageHeight) );
var dragxy:String = "";
function onDown(e:MouseEvent):void
{
dragxy = mouseX + "_" + mouseY;
e.currentTarget.startDrag(false, constrainY);
removeEventListener(MouseEvent.MOUSE_DOWN, onDown);
addEventListener(MouseEvent.MOUSE_UP, onUp);
}
function onUp(e:MouseEvent):void
{
e.currentTarget.stopDrag();
addEventListener(MouseEvent.MOUSE_DOWN, onDown);
removeEventListener(MouseEvent.MOUSE_UP, onUp);
}
答案 0 :(得分:0)
缓动函数的一个简单示例是:
private function easeTo(obj:MovieClip,currentGoalx:Number,currentGoaly:Number,easeFac:Number):void{
obj.x += (currentGoalx-obj.x)/easeFac;
obj.y += (currentGoaly-obj.y)/easeFac;
}
首先你需要一个计时器或输入帧循环,例如这个添加到舞台:
addEventListener(Event.ENTER_FRAME,enterFrame);
然后在你的enterFrame函数中执行以下操作:
private function enterFrame(e:Event):void{
easeTo(box,stage.mouseX,stage.mouseY,3);
}
3的easeFac比2的easeFac更缓慢,更平滑,4更平滑,更有效。
或类似的东西。这个想法是obj在每次函数调用时距离目标一半。因此,如果在每一帧都调用此功能,您将获得顺畅的“轻松”功能。影响。如果你将currentGoal设置为鼠标位置,那么obj将跟随鼠标的任何位置,但不是1:1的匹配,而是跟踪并顺利追赶。