1

我正在构建一个游戏,其中界面是首先加载到屏幕上的项目之一。声音按钮,暂停和所有的位 -

在游戏过程中 - 所有庄园的东西都被动态添加和删除到舞台上。因此我的界面在我的游戏场景后面。

如何确保影片剪辑始终保持在最前面?

我可以覆盖我的文档类的 addChild 并且每次添加新的孩子时,我都会将界面重新堆叠到顶部?

4

3 回答 3

1

查看 addChildAt,它允许您指定也应添加新对象的索引。

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#addChildAt%28%29

一个好的策略是将所有界面元素保存在一个父 Sprite/MovieClip 中,并将所有游戏资源保存在另一个中。(上面有一个接口)

于 2010-03-31T05:22:33.977 回答
1

您可以使用 setChildIndex 重新排列已包含在 MovieClip 或 Sprite 中的对象。例如,如果您有一个名为container的对象,其中包含一个 redBall、blueBall 和许多其他球对象,您可以使用以下内容确保 redBall 位于其他所有对象后面:

container.setChildIndex(redBall, 0);

同样,您可以使用以下方法确保 blueBall 将显示在其他所有内容的前面:

container.setChildIndex(blueBall, container.numChildren-1);

addChildAt将整理您以将孩子直接添加到正确的位置,并且 setChildIndex 将允许您重新定位已放置的对象。希望有帮助。

得不

于 2010-03-31T06:16:43.427 回答
0

显然,根据您的建议,如果您 addChild 一个对象已经在屏幕上,它只是重新索引到顶部。这看起来好吗?

private var topLevelChildrenArray:Array = [];

public function addTopLevelChild(child:DisplayObject):DisplayObject
{
    topLevelChildrenArray.push(child)
    return this.addChildAt( child, this.numChildren - 1 );  
}

override public function addChild(child:DisplayObject):DisplayObject
{
    this.addChildAt(child, this.numChildren);

    for each(var topChild:DisplayObject in topLevelChildrenArray)
    {
        super.addChild(topChild);
    }

    return child
}
于 2010-03-31T18:28:33.593 回答