代码之家  ›  专栏  ›  技术社区  ›  Glycerine

动作脚本中的电影剪辑叠加

  •  1
  • Glycerine  · 技术社区  · 14 年前

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

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

    我如何确保电影剪辑始终保持在顶部?

    我可以重写文档类的addchild吗?每次添加新的子类时,我都会将接口重新锁定到顶部?

    3 回复  |  直到 10 年前
        1
  •  1
  •   debu    14 年前

    可以使用setchildindex重新排列已包含在movieclip或sprite中的对象。例如,如果有一个名为 容器 ,其中包含红球、蓝球和许多其他球对象,您可以使用以下命令确保红球位于其他所有对象之后:

    container.setChildIndex(redBall, 0);
    

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

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

    addChildAt 将对直接将子对象添加到其正确位置进行排序,setChildIndex将允许您重新定位已放置的对象。希望能有所帮助。

    调试

        2
  •  1
  •   Tyler Egeto    14 年前

    在addchildat中,它允许您指定应该添加新对象的索引。

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

    一个好的策略是将所有界面元素保存在一个父精灵/电影剪辑中,而将所有游戏资源保存在另一个父精灵/电影剪辑中。(接口在上面)

        3
  •  0
  •   Glycerine    14 年前

    根据你们的建议,很明显,如果你在屏幕上添加了一个对象,它只是重新索引到顶部。这个看起来还好吗?

    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
    }