0
我需要根據鼠標拖動使MovieClip圍繞其中心點向左或向右旋轉。我得到了一些我想要的東西的基本表象,但它很駭人聽聞。通常我會計算角度等,但我只需要使用鼠標移動的距離並將其應用到動畫片段,並且在放手時添加一些很好的緩動。在ActionScript中拖動,旋轉和放鬆
public function Main()
{
var wereld:MainScreen = new MainScreen();
addChild(wereld);
wereld.x = -510;
planet = wereld["planet"];
wereld.addEventListener(MouseEvent.MOUSE_DOWN, startRotatingWorld);
}
private function startRotatingWorld(e:MouseEvent):void
{
m_mouseStartPos = stage.mouseX;
stage.addEventListener(MouseEvent.MOUSE_UP, stopRotatingWorld);
stage.addEventListener(Event.MOUSE_LEAVE, stopRotatingWorld);
}
private function applyRotationToWorld(e:MouseEvent):void
{
//Calculate the rotation
var distance:Number = (m_mouseStartPos - stage.mouseX)/10000;
//apply rotation
planet.rotation += -distance //* 180/Math.PI;
}
private function stopRotatingWorld():void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, applyRotationToWorld);
}
我發現了另一個我實現的解決方案。如果你想我可以展示給你。然而,你的答案是相當不錯的,因爲你的解決方案,所以我會把它設置爲解決:) – Zophiel