Actionscript 中的影片剪辑堆叠
我正在构建一款游戏,其界面是屏幕上首先加载的项目之一。声音按钮、暂停和所有的部分 -
在游戏过程中 - 所有庄园的东西都会动态地添加和删除到舞台上。因此我的界面位于我的游戏场景后面。
如何确保影片剪辑始终位于最前面?
我是否可以覆盖文档类的 addChild 并在每次添加新子项时将界面重新堆叠到顶部?
I'm building a game of which the interface is one of the first items to load on screen. Sound button, pause and all the bits -
During the game - all manor of things are dynamically added and removed to the stage. Therefore my interface goes behind my game scene.
How do I ensure the movieclip always stays on top?
Can I override the addChild of my Document Class and every time a new child is added, I restack the interface to the top?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 setChildIndex 重新排列已包含在 MovieClip 或 Sprite 中的对象。例如,如果您有一个名为 container 的对象,其中包含 redBall、blueBall 和许多其他球对象,您可以使用以下命令来确保 redBall 位于其他所有对象的后面:
同样,您可以确保blueBall 将显示在其他所有内容的前面,使用:
addChildAt
将帮助您将子项直接添加到正确的位置,而 setChildIndex 将允许您重新定位已放置的对象。希望有帮助。德布
You can use setChildIndex to rearrange objects that are already contained within a MovieClip or Sprite. For example, if you have an object called container, which contains a redBall, blueBall and many other ball objects, you can use the following to make sure redBall is behind everything else:
Equally you can make sure that blueBall will be displayed infront of everything else using:
addChildAt
will sort you out for adding children straight into their correct position, and setChildIndex will allow you to re-position objects already placed. Hope that helps.debu
查看 addChildAt,它允许您指定新对象也应添加的索引。
http://livedocs.adobe。 com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#addChildAt%28%29
一种好的策略是将所有界面元素保留在一个父 Sprite/MovieClip 中,并将所有游戏资源保留在另一个父 Sprite/MovieClip 中。 (接口在上)
Look into addChildAt, it allows you to specify the index that the new object should be added too.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#addChildAt%28%29
A good strategy is to keep all interface elements in one parent Sprite/MovieClip, and all game assets in another. (With the interface one on top)
根据你们的建议,我做了这个,显然,如果您 addChild 一个已经在屏幕上的对象,它只是重新索引到顶部。这看起来还好吗?
With your guys suggestion I made this, apparently, if you addChild an object already on the screen, it's simply reindex'd to the top. Does this look ok?