2013-04-07 95 views
0

我對flash和AS3真的很陌生,所以我甚至不知道如何正確地提出這個問題。AS3 addchild保持動畫運動的動畫片段

我有一個角色(MovieClip)有一個動畫,我想要做的就是向這個角色添加一個項目,例如在「head」圖層中,這個項目應該跟在「head」圖層之後。
因此,意味着每個框架中的物品應該略高於頭部,並且頭部不斷地改變其位置。

到目前爲止,我得到的是一個靜態項目(永遠不會隨頭層移動),並將其與「addchildat」添加到我的動畫片段中。

var running : anim_running = new anim_running(); // running movieclip 
var cono : i_1 = new i_1(); // cone head item 
running.addChildAt (cono, 10); // adding the cone to the proper layer 
cono.x = 20; 
cono.y = -20; // positioning the cone on top of the head 

與這段代碼,這是什麼樣子(我不能發表圖片還)

http://oi45.tinypic.com/2qx6bls.jpg - 這是錐正確定位
http://oi47.tinypic.com/34g6bub.jpg框架 - 但在未來框架的錐不會跟隨頭層

對不起,如果這是一個真正的菜鳥問題。在詢問之前,我搜索了全部谷歌。

非常感謝提前!

回答

0

也許最簡單的方式做到這一點(有沒有太多棘手的代碼),將創建頭影片剪輯內部的「容器」影片剪輯,您可以在新帽子加影片剪輯。

然後只是將帽子添加到容器。確保你有你的實例名稱設置,以便你可以在代碼中引用它們。這裏是一個例子:

running.head.hatContainer.addChild(cono); 
+0

這很有道理!謝謝 :) – 2013-04-07 05:19:59

0

好吧,所以如果我正確理解這一點,你會想添加一個容器影片剪輯,其頭部和錐體都在裏面。然後,您將爲容器製作動畫而不是頭部。這樣,您可以將容器相對於其他項目添加到容器中,就好像它是靜態的並且動畫一直播放。

粗糙例如:

var container:MovieClip = new MovieClip(); 
addChild(container); 
container.addChild(head); 
container.addChild(cone); 

TweenLite.to(container, 3, {x:container.x + 50}); /*head and cone move relative to each other because their parent is being animated */