Game Development Community

Gui help?

by 2dGamer · in Torque 2D Beginner · 02/02/2014 (5:22 am) · 6 replies

I need to make a ctrl that changes images when clicked(not ondown), is this possible?

#1
02/02/2014 (7:17 am)
Ok, when clicked. That usually happens onMouseDown()/onTouchDown(). How can you click without clicking?

Or do you mean you want it to change when you release the mouse? Which is onMouseUp()/onTouchUp().

Or do you mean like a toggle button?

Or a check box?

Or a radio button?

Otherwise I'm lost here - you really should try to describe what you want as clearly as possible.
#2
02/02/2014 (3:57 pm)
Sorry,I typed it a bit quick. I was wanting a control that when clicked it changes the image and stays changed after it is released till it's clicked again... (I'm trying to make a Keno game and need each number to act as a button)
#3
02/02/2014 (5:38 pm)
So you want a toggle button. Luckily, that's a normal GuiImageButtonCtrl and the type is determined by the buttonType property like so:
<GuiImageButtonCtrl
        canSaveDynamicFields="0"
        isContainer="0"
        Profile="GuiDefaultProfile"
        HorizSizing="right"
        VertSizing="bottom"
        Position="22 15"
        Extent="35 30"
        MinExtent="8 2"
        canSave="1"
        Visible="1"
        Active="1"
        tooltipWidth="250"
        hovertime="1000"
        groupNum="-1"
        buttonType="ToggleButton"
        NormalImage="ToyAssets:TD_Crystal_greesSprite"
        DownImage="ToyAssets:TD_Crystal_blueSprite"
        useMouseEvents="0" />
Since it's buttonType is "ToggleButton" it should stay down when clicked, and pop back up when clicked again. It should show the NormalImage when it is up and the DownImage when it is down.
#4
02/03/2014 (3:42 am)
Is there a way to programmatically change the current image the button is using without triggering the button? for example :

The are the buttons : 1,2,3

1 is not toggled.
2 is toggled.
3 is toggled.

Two random numbers are chosen (1-3) and 2 and 3 get selected

I want to change 2 & 3s image temporarily till the "play again" button is clicked.

Do you understand what I'm trying to say?
#5
02/03/2014 (6:40 am)
Yes. Give the button a name:
<GuiImageButtonCtrl  
        name="MyToggleButton"
        canSaveDynamicFields="0"  
        isContainer="0"  
        Profile="GuiDefaultProfile"  
        HorizSizing="right"  
        VertSizing="bottom"  
        Position="22 15"  
        Extent="35 30"  
        MinExtent="8 2"  
        canSave="1"  
        Visible="1"  
        Active="1"  
        tooltipWidth="250"  
        hovertime="1000"  
        groupNum="-1"  
        buttonType="ToggleButton"  
        NormalImage="ToyAssets:TD_Crystal_greesSprite"  
        DownImage="ToyAssets:TD_Crystal_blueSprite"  
        useMouseEvents="0" />
Then, you can set the DownImage at run-time:
if(%condition == 1)
{
  MyToggleButton.DownImage = "ToyAssets:TD_Crystal_blueSprite";
}
if(%condition == 2)
{
  MyToggleButton.DownImage = "ToyAssets:TD_Crystal_redSprite";
}
Or you can use an array to hold many buttons and iterate through the whole set without using names - but this is a little more complex. Or you can use a container like another GuiControl to hold the buttons in and then just iterate through them using GuiControl.getObject(%index).... Cats and skinning....
#6
02/03/2014 (7:22 am)
Thanks. I'm jumping from C# and XNA to torque so bear with me...