2011-06-27 92 views
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); 
    } 

回答

1

這裏的來源和可能的解決方案演示給你: http://wonderfl.net/c/o8t0

我根據基思彼得minimalcomps拖動旋轉檢測,特別是sourceknob component

Minimal Comp's Knob source,你可以在'onMouseMoved'函數中獲得旋轉,水平和垂直移動。

最後我用​​來處理寬鬆回來。在我的代碼中,我調用了'this'對象,但實際上,您應該在您正在補間並補間該項目的對象中創建一個公共值,以便您可以更輕鬆地補間一個項目。

如果這是面向公衆的項目,請告訴我您何時實施它;不介意看看它是什麼^ _^

+0

我發現了另一個我實現的解決方案。如果你想我可以展示給你。然而,你的答案是相當不錯的,因爲你的解決方案,所以我會把它設置爲解決:) – Zophiel