2012-06-06 53 views
1

我想添加功能到我的照片庫 - 不同類型的照片的拇指動畫。現在我確實喜歡下面的代碼。一切正常,但我希望拇指從舞臺的邊緣反彈。簡單的as3動畫模式

而且最重要的是,我需要動畫的不同模式 - 運動作爲3D旋轉木馬,在一個圓圈旋轉,太陽光線的運動和背部等

,如果你有一個我將不勝感激現成的這些和類似動畫的代碼片段。

[Bindable] private var stageW:int = Capabilities.screenResolutionX; 
[Bindable] private var stageH:int = Capabilities.screenResolutionY; 

private var itemsVector:Vector.<Image>=new Vector.<Image>(); 
private var xSpeedVector:Vector.<Number>=new Vector.<Number>(); 
private var ySpeedVector:Vector.<Number>=new Vector.<Number>(); 

stage.addEventListener(Event.ENTER_FRAME, update); 

private function moveSetup():void { 
for(var i:int = 0; i < FlexGlobals.topLevelApplication.objects.length; i++){ 
    if (FlexGlobals.topLevelApplication.objects[i] is Image){ 
     var item:Image=FlexGlobals.topLevelApplication.objects[i] as Image; 
     item.x=Math.random()*stageW; 
     item.y=Math.random()*stageH; 
     var randomDirection:Number=Math.random()*2*Math.PI; 
     this.addElement(item); 
     itemsVector.push(item); 
     xSpeedVector.push(2*Math.cos(randomDirection)); 
     ySpeedVector.push(2*Math.sin(randomDirection)); 
    } 
} 
} 

protected function update(event:Event):void { 
    for(var i:uint=0;i<itemsVector.length;i++){ 
     itemsVector[i].x+=xSpeedVector[i]; 
     itemsVector[i].y+=ySpeedVector[i]; 
     if(itemsVector[i].x>stageW){ 
      itemsVector[i].x-=stageW; 
     } 
     if(itemsVector[i].x<0){ 
      itemsVector[i].x+=stageW; 
     } 
     if(itemsVector[i].y>stageH){ 
      itemsVector[i].y-=stageH; 
     } 
     if(itemsVector[i].y<0){ 
      itemsVector[i].y+=stageH; 
     } 
    } 
} 
+0

[Stack Overflow不是您的個人研究助理](http://meta.stackexchange.com/a/128553/157159) –

+0

ОК。 「我希望大拇指從舞臺邊緣反彈。」 – Astraport

回答

1

看一看Greensock's TweenLite library這是相當多的在Flash動畫(和,作爲額外的獎勵,最近一直ported to JavaScript)的標準。

它支持各種設置緩動功能,包括反彈功能。該庫的付費版本甚至包括創建自定義緩動功能的功能。在我鏈接到的第一頁中間有一個交互式演示,您可以在該庫中直播並測試各種緩動功能。

谷歌搜索將出現各種教程,講解如何構建(僞)3D軌道傳送帶以及執行相同操作的第三方組件。事實上,這些實現相對簡單,就像他們所做的那樣,只需簡單的三角函數即可。 This example似乎會爲您調整以適應您的特定要求提供合理的起點。

3D效果當然可以在Flex中實現。我建議你看看Away3D這是一個爲Flash平臺編寫的開源3D庫。有一個在Away3D中實現的水平螺旋效應的示例(以及完整的源代碼)可用here

+0

謝謝net.uk.sweet。我經常使用這個庫。我忘了提及這些對象將是相當多的(10-20),以及移動設備的應用程序。我認爲會花費太多資源。我正在尋找類似的例子:http://www.guahanweb.com/2009/02/03/circular-rotation-and-orbiting-in-as3/ – Astraport

+0

你鏈接的例子有什麼問題? –

+0

沒問題。相反,我正在尋找簡單的動畫例子,如鏈接。 – Astraport