Layering Children


06-10-2009 20:36:50


I'm trying to create a HUD for my game. Right now I have 3 separate components: the main face of the HUD, an element that slides out from the main face, and a button (which is really just a StaticImage) on the sliding element.

GUIStaticImage* mFace = (StaticImagePtr)(mGUI->createWidget("StaticImage", "StaticImage", 128, 350, 365, 175, MyGUI::Align::Left, "Back", "wristWatch"));

GUIStaticImage* mSlider = (StaticImagePtr)(mGUI->createWidget("StaticImage", "StaticImage", -78, 30, 255, 128, MyGUI::Align::Left, "Back", "abilitySlider"));

GUIStaticImage* mButton = (StaticImagePtr)(mGUI->createWidget("StaticImage", "StaticImage", 48, 32, 50, 50, MyGUI::Align::Left, "Back", "abilityButton"));

(I'm reinterpreting the MyGUI wrapper that I wrote, so please forgive me if my syntax is a little off)

This produces the ability button on top of the slider, which is correct. However, the slider appears on top of the main face, which is opposite of what I need. I tried using LayerManager::upLayerItem(...) to bring the main face to the top of the layer, but the slider still appeared on top. I tried changing the widget style of the slider to MyGUI::WidgetStyle::Overlapped and the placement of the widgets went crazy. Is there some other function or property to set the layering of widgets and their children?

I do not have screenshots at the moment, but will gladly post some if they will help.



06-10-2009 21:41:51

I'm a bit confused - I don't understand what you need and what you got.
Right now I can give you two advices that might help:
1) I see no reasons to create root widget and then attaching it - just use mFace->createWidget(...) instead mGUI->createWidget and attachToWidget/setWidgetStyle.
2) Try using overlapping layers if you have widgets on one layer that overlap: change "Back" to "Overlapped"


06-10-2009 22:58:32

Thank you for the response.

Maybe this will help.

The order of visibility I want is as follows:

  1. mFace (front)
    mButton (middle)
    mSlider (back)

    What I am getting is this:

    1. mButton (front)
      mSlider (middle)
      mFace (back)

      Is that any clearer?

      I am creating a root widget and then attaching/detaching widgets because I need to be able to add and remove images as the game progresses.
      I tried changing the layer to "Overlapped" but the positions of the widgets but the same improper order was produced.

      My other guess was that the widgets were being drawn in improper order because I create them in that order (mFace, mSlider, mButton). However I changed my code to create the widgets in a different order (mSlider, mButton, mFace) but that produced no changes.



07-10-2009 00:23:03

I am creating a root widget and then attaching/detaching widgets because I need to be able to add and remove images as the game progresses.I see no sense in this sentence. :/
mFace->attachToWidget(mFace);What this mean?
mSlider->attachToWidget(mButton);Why you attaching slide to button if you want to have slide under button? Reverse it.

And afterall - I still don't understand how it all should look like, but use three different layers if you want to have widgets in different layers.

P.S. Sorry if it sounds a bit agressive, but I don't understand what are you doing and why you doing it so ...


07-10-2009 15:09:48

sorry, those were mistakes on my part. This is what I have in code:




I was going upload some images to post here, but my server is currently down. Let me explain the HUD to you.

The main face is the primary part of the HUD. This is generally the only component visible to the player during the game.
When the player clicks on the face, a bar slides out to the right. This 'slider' can contain different items, including 'ability buttons.'
Each ability button corresponds to an ability that the player acquires over the course of the game. These ability buttons are added to or removed from the slider when abilities are acquired or lost.

The ability buttons need to be drawn on top of the slider so that the user can click on a button to activate an ability. These objects currently render in the correct order.
The slider needs to be drawn behind the main face so that the slider is hidden until the player clicks on the face. Right now, the slider renders on top of the main face.

If you need further explanation for any of this, please let me know.

Now, you asked why I am creating a root widget and then attaching or detaching widgets to that root instead of using mFace->createWidget(...). The slider is the root widget for all of the ability buttons. I create this widget first because it must always be available to the player. However, the ability buttons need to be created, destroyed, or hidden at appropriate times in the game. I am therefore creating ability buttons as they are needed and attaching/detaching them from the slider.

I really appreciate your patience with this.



07-10-2009 16:04:36

Also, I tried using mFace->createWidget(...) and mSlider->createWidget(...) and still had the same results.


13-10-2009 14:36:32

I never was able to figure this out, but I worked around it by using a layout instead of creating the widgets in code. I don't parent the slider to the main face and put them on separate layers to get the drawing order that I needed.