Game Development Community

Layer Problem of GUIText and GUIBitmap

by kinleong · in Torque X 2D · 07/19/2009 (8:28 am) · 3 replies

Hi all,

I got a little problem in building the GUI. I would like to combine a GUIText and GUIBitmap in almost the same position which act like layering. However, no matter how I change the order of creating the object of GUIText and GUIBitmap, the GUIBitmap always shows on top of the GUIText. I set the GUIText.Layer = 0, but it doesn't work. What can I do? Thanks.

#1
07/19/2009 (10:53 am)
What is the parent of the GUIText and Bitmap? Are they directly below the GUICanvas?

I believe Layer only applies to GUIControls which are immediate children of the GUICanvas. For a control lower in the hierarchy, after its parent renders, it is rendered, then any children it has, then any siblings that haven't been rendered, yet (i.e. depth-first). The order relative to its siblings is the order they were added to their parent.
#2
07/19/2009 (9:11 pm)
I followed John's book Cheapter 16. Here is my code:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.Platform;
using GarageGames.Torque.Core;
using GarageGames.Torque.Sim;
using GarageGames.Torque.GUI;
using GarageGames.Torque.MathUtil;
using GarageGames.Torque.T2D;

namespace StarterGame2D
{
    public class GuiPlay : GUISceneview, IGUIScreen
    {
        public GuiPlay()
        {
            GUIStyle playStyle = new GUIStyle();
            Name = "GUIPlay";
            Style = playStyle;
            Size = new Vector2(800, 600);

            _style = new GUIStyle();

            _textStyle = new GUITextStyle();
            _textStyle.FontType = "arial16";
            _textStyle.TextColor[0] = Color.WhiteSmoke;
            _textStyle.SizeToText = true;

            _setHpValueBoard("RightUp", _kHpValueBoard, new Vector2(1050, 0));
            _setGuiCharactersEmotion("GiantMartin", _giantMartin, new Vector2(0, 0));
            _setGuiCharactersEmotion("DruggyDog", _druggyDog, new Vector2(0, 480));
            _setGuiCharactersEmotion("K", _k, new Vector2(1170, 35));
            _setHpValueText("K", _kHpText, new Vector2(1050, 0));


        }

        private void _setGuiCharactersEmotion(string name, GUICharactersEmotion characterEmotion, Vector2 characterPosition)
        {
            characterEmotion = new GUICharactersEmotion(name, characterPosition);
            characterEmotion.Style = _style;
            characterEmotion.Visible = true;
            characterEmotion.Folder = this;
            this.OnGUIWake += characterEmotion.OnWakeUp;
        }

        private void _setHpValueBoard(string cornerName, GUIHpBoard hpBoard, Vector2 cornerPosition)
        {
            hpBoard = new GUIHpBoard(cornerName, cornerPosition);
            hpBoard.Style = Style;
            hpBoard.Visible = true;
            hpBoard.Folder = this;
            hpBoard.Layer = 5;
            this.OnGUIWake += hpBoard.OnWakeUp;
        }

        private void _setHpValueText(string name, GUIText guiText, Vector2 textPosition)
        {
            guiText = new GUIText();
            guiText.Name = name + "Hp";
            guiText.Style = _textStyle;

            guiText.Text = "100%";
            guiText.Position = textPosition;
            guiText.Visible = true;
            guiText.Folder = this;
        }

        GUICharactersEmotion _giantMartin;
        GUICharactersEmotion _druggyDog;
        GUICharactersEmotion _k;

        GUIHpBoard _kHpValueBoard;
        GUIText _kHpText;
        GUITextStyle _textStyle;

        GUIStyle _style;
    }
}

I just used a class called GUIPlay which implement GUISceneview and IGUIScreen. No matter how I changed the order of _setHpValueText and _setHpValueBoard, the GUIBitmap always on top of the GUIText that I specified. Did I did something wrong here? Thanks.
#3
07/19/2009 (10:04 pm)
I'm not sure why the bitmap is always on top there. Maybe it would work to have the text as a child of the board, ala guiText.Folder = hpBoard;? Of course, if you were to try that, the text position would be relative to the board; wherever its upper-left corner is would be 0,0 to the text.

With the code as it, you could try tracing into the code (assuming you have access to the Torque source). When the objects are added to the GuiPlay, look at the order they go into its array of children.

Then, when the GUI hierarchy is rendered, step through the rendering process starting with the GuiPlay and see what happens as it renders its children. Maybe you'll be able to see what is going on.

Good luck.