Game Development Community

GUI

by yurembo · in Torque 2D Beginner · 09/03/2013 (10:41 am) · 5 replies

Hello all!
how could I create gui items? I created a button in a script, this is well, but this button fills whole window however I turn property "Extent" to a correct size. I need that this button looks like a simple button.

#1
09/03/2013 (11:20 am)
Here is one of my buttons:
// Clear particle 2
            new GuiBitmapButtonCtrl() {
               canSaveDynamicFields = "0";
               Enabled = "1";
               isContainer = "0";
               Profile = "ToolsGuiButtonProfile";
               HorizSizing = "left";
               VertSizing = "bottom";
               position = "56 1";
               Extent = "17 17";
               MinExtent = "8 2";
               canSave = "1";
               Visible = "1";
               Command = "%particleId = GraphEE_EmitterParticle2-->PopUpMenu.findText( \"None\" ); GraphEE_EmitterParticle2-->PopUpMenu.setSelected( %particleId );PE_EmitterEditor.updateParticlesFields();"; 
               hovertime = "1000";
               tooltip = "Clear Particle 2 from Emitter";
               text = "";
               bitmap = "tools/gui/images/clear-icon";
               groupNum = "-1";
               buttonType = "PushButton";
               useMouseEvents = "0";
            };

It sounds like your issue has to do with the horizSizing and vertSizing:
HorizSizing = "left";
VertSizing = "bottom";
What did you set these to on your button? Try playing with the values a bit.
#2
09/03/2013 (11:36 am)
it doesn't help
my cod:

%button = new GuiButtonCtrl()
{
canSaveDynamicFields = "0";
HorizSizing = "left";
Enable = true;
VertSizing = "bottom";
isContainer = "0";
Profile = "BlueButtonProfile";
Position = "5 1";
Extent = "17 17";
Visible = "1";
isContainer = "0";
Active = "1";
text = "OK";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
};
Canvas.pushDialog(%button);

I think the last line is incorrect, could it be?
#3
09/03/2013 (12:28 pm)
Sure, Canvas.pushDialog(%button); is incorrect, instead I use another scene object, and it's right

P.S. Excuse me, I write my first T2D game
#4
09/03/2013 (5:14 pm)
Ok, if your button is the only control it will automatically fit itself to the canvas. You should create a GuiControl and add the button to it; the GuiControl will fill the canvas and your button will be placed and sized as designed.

Take a quick look at this thread, it should help a little.
#5
09/04/2013 (4:11 am)
Ah yeah now I understand what you meant by it filling the whole window.
Basically
Canvas.pushDialog(%control);
Sets the content of the whole T3D window. Canvas is the parent-GUI that all other UI Elements are added to so when you push a dialog to the canvas it's like setting everything that should be in the window to be that dialog.

What you want to do is add the button to the relevant GuiControl (e.g. the mainmenu gui)