如何解决在AS3的阶段重叠对象如何解决、对象、阶段

2023-09-09 21:34:52 作者:可爱爆了

我有一个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.