如何在 AS3 中修复舞台上重叠的对象 [英] How to fix overlapping objects on the stage in AS3

查看:19
本文介绍了如何在 AS3 中修复舞台上重叠的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Flash 游戏,我有一张图片被设计为提示文本框,里面有相关文本的文本框,但文本框被图像隐藏了.任何人都知道如何制作以便保证文本框位于顶部或我需要做的任何事情来防止这种情况发生?

I have a flash game where I have a picture designed to be the textbox for a prompt and textbox inside with the relevant text but the textbox is being hidden by the image. Anyone know how to make is so that the textbox is guaranteed to be on top or whatever I need to do to keep this from happening?

推荐答案

使用 setChildIndex 的另一个答案肯定会起作用,但是,我认为您应该采取不同的设计方法来删除完全头疼.

The other answer using setChildIndex will definitely work, however, I think a different design approach is really what you should be doing to remove the headache altogether.

例如在游戏中我可能有不同的层,例如:

For example in a game I might have different layers such as :

backgroundLayer
gameLayer
interfaceLayer

这 3 个 Sprite 层将按该顺序添加到舞台上.然后我会将显示对象添加到适当的图层.因此,我添加到 backgroundLayer 或 gameLayer 的任何内容都将始终位于 interfaceLayer 上我的用户界面的后面".

Those 3 Sprite layers would get added to the stage in that order. I would then add display objects to the appropriate layers. So anything I added to the backgroundLayer or gameLayer would ALWAYS be 'behind' my user interface on the interfaceLayer.

这让您不必担心不断分层.setChildIndex 的答案将在那一刻解决问题,但如果向容器中添加其他内容,它会与您的文本框重叠,这是我不认为您想要的.

That allows you to not have to worry about the layering constantly. The answer with setChildIndex will fix the problem for that moment, but should something else be added to the container it will overlap your textbox, which is something I don't assume you want.

这是一个例子:

var backgroundLayer:Sprite = new Sprite;
var gameLayer:Sprite = new Sprite;
var interfaceLayer:Sprite = new Sprite;

addChild(backgroundLayer);
addChild(gameLayer);
addChild(interfaceLayer);

现在,无论您向 interfaceLayer 添加什么,都将始终位于您添加到 gameLayer 或 backgroundLayer 的对象之上.

now, whatever you add to interfaceLayer, will ALWAYS be on top of objects you add to gameLayer or backgroundLayer.

因此,就您的文本框而言,只需将其添加到 interfaceLayer 以及您想要在其后面的任何其他对象,添加到 gameLayer 或 backgroundLayer.

So in the case of your text box, just add it to your interfaceLayer and any other objects you want behind it, you add to the gameLayer or backgroundLayer.

这篇关于如何在 AS3 中修复舞台上重叠的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆