我正在用Flash CS5/AS 3.0編寫遊戲,試圖通過基於Y位置的升序來繪製所有相關的電影剪輯來模擬景深,也就是說舞臺上較低的東西與舞臺上的東西重疊。因此,與Y位置爲20的MovieClip相比,Y位置爲10的MovieClip因此需要較低的索引,因此第二個位於第一個位置上。基於Y位置更改動畫片段的子索引?
我寫了一個快速而髒的函數來測試這個。在追蹤過程中,我注意到當我靠近舞臺頂部時,卡車的索引達到0,但如果我走得太遠,它將完全從舞臺上消失。跟蹤然後開始產生這樣的錯誤:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/getChildIndex()
at EICT::Game/ReorganizeDisplayIndexes()
at EICT::Game/loop()
theTruck是玩家控制的車輛 敵人的電影剪輯,錐,岩石是含有影片剪輯
他們都沒有事件偵聽所有陣列。
private function ReorganizeDisplayIndexes(): void
{
var drawableObjects:Array = new Array();
drawableObjects.push(theTruck);
drawableObjects = drawableObjects.concat(Enemies, Rocks, Bushes);
drawableObjects.sortOn("y", Array.DESCENDING | Array.NUMERIC);
drawableObjects.reverse();
trace(collisionLayer.getChildIndex(theTruck));
for (var a:int = collisionLayer.numChildren - 1; a >= 0; a--)
{
collisionLayer.removeChildAt(a);
}
for (var i:int = 0; i < drawableObjects.length; i++)
{
collisionLayer.addChild(drawableObjects[i]);
}
}
謝謝,我已經繞過它,事實證明,這一點的代碼甚至不負責讓卡車消失在第一位。但我仍然會使用這種方法。 – 2012-03-01 14:11:28