Layer Prop not working on GuiText and GuiButton (Solved)
by Robert Schmidt · in Torque X 2D · 05/05/2008 (4:54 pm) · 9 replies
I am creating buttons in the OnSceneLoaded method of my GameManager, setting the layer property to the same as other buttons defined in the scene file (20). Despite that they remain on the top layer obscuring the mouse icon on hover. This happens with both the GuiText and GuiButton objects. Has anyone else experienced this? Is there a work around? Should I be creating data driven content somewhere else, in another method?
Any help would be appreciated.
Any help would be appreciated.
About the author
#2
05/06/2008 (5:43 am)
The mouse is a static sprite and is in the database. It does hover correctly over other objects that are initialized via the scene file. Maybe I shouldn't be using guicontrols.
#3
Thats what I meant, was if it is a static sprite or animated sprite. I think it would have to be a GUI bitmap, or a GUI drawn shape of some kind. That way it would have a chance of being drawn after your other GUI bitmap layers.
GUI controls are an intergal part of the TorqueX engine, I really don't see how you can get around using them. But I know for a fact, you can fake a GUI layer using static sprites.. so...
I could be wrong and, what you are trying to do may be possible, but first I would try just using two or three GUI layers, the stuff in your scene, in the torque Object database, you Bitmap GUI layer, and your mouse on top of everything else using a GUI bitmap
Will-O
05/06/2008 (7:25 am)
Quote:
The mouse is a static sprite and is in the database
Thats what I meant, was if it is a static sprite or animated sprite. I think it would have to be a GUI bitmap, or a GUI drawn shape of some kind. That way it would have a chance of being drawn after your other GUI bitmap layers.
Quote:
Maybe I shouldn't be using guicontrols.
GUI controls are an intergal part of the TorqueX engine, I really don't see how you can get around using them. But I know for a fact, you can fake a GUI layer using static sprites.. so...
I could be wrong and, what you are trying to do may be possible, but first I would try just using two or three GUI layers, the stuff in your scene, in the torque Object database, you Bitmap GUI layer, and your mouse on top of everything else using a GUI bitmap
Will-O
#4
1) Scenario 1
2) Scenario 2
3) Scenario etc...
The user can then click on an entry to lauch a new game.
I am using different layers, it just seems that GuiControls ignore this and place themselves on the top layer no matter what. I guess I could change the mouse icon from a sprite to a guibitmap and see if that helps. I don't know if I can mount a guicontrol to a sprite though. And now that I think about it I may have a problem getting the mouse pointer to collide with the GuiButtons.
It would be nice if GG provided some tutorials on how to use the mouse to interact with scene objects.
05/06/2008 (10:28 am)
I am using the collision properties of sprites and animated sprites to provide hover effects for mouse interaction. I don't know if GuiControls have the ability to "collide" with other scene objects. I am trying to dynamically populate a list of scenarios based on the contents of a directory so I want to have text buttons like so;1) Scenario 1
2) Scenario 2
3) Scenario etc...
The user can then click on an entry to lauch a new game.
I am using different layers, it just seems that GuiControls ignore this and place themselves on the top layer no matter what. I guess I could change the mouse icon from a sprite to a guibitmap and see if that helps. I don't know if I can mount a guicontrol to a sprite though. And now that I think about it I may have a problem getting the mouse pointer to collide with the GuiButtons.
It would be nice if GG provided some tutorials on how to use the mouse to interact with scene objects.
#5
Good luck
Will-O
05/06/2008 (11:13 am)
You might consider creating a blank scene object, for your mouse collisions, and visually reprsenting it with a GUI Layer which is passed its coordinates form the sprite. You may run into some difficulties, I can only point you in a general direction. One of the difficulties you may encounter, it used to be that GUI and scene coordinates are not easly converted, one to the other, you may find a resource somewhere that helps with the conversion, or maybe theres is some torquex api to handle it. Good luck
Will-O
#6
Thanks Will for your help.
05/07/2008 (12:41 pm)
Just to confirm...I found the code in the GuiSceneView.OnRender that is responsible for this issue. As I suspected the renderer calls the renderer for the objects first then the gui so regardless of the value of the layer property guicontrols will always overwrite scene objects. So, my options are to make the mouse cursor a guibutton and position it over the mouse pointer. This is alot more difficult than I thought as I am unable to bind the cursor's GuiButton to the pointer's static sprite. Or, I can try to render dynamic text as a static sprite. Don't know if it is possible. Thanks Will for your help.
#7
You can try putting this into a new class that derives from T2DStaticSprite:
Use this class to create the text and you shoudl also be able to set the layer also. In the code above you can use FontRenderer method or DrawUtil.JustifiedText to draw the text but I have DrawUtil.JustifiedText commented out above.
05/10/2008 (8:13 pm)
It seems weird that you'd be using GUIButton for a mouse icon. I'd probabaly try a different way to render text than GUIText, because I think GUIText was designed to be in front no matter what because it's the GUI.You can try putting this into a new class that derives from T2DStaticSprite:
class T2dSceneObjectWithText: T2DStaticSprite
{
GUITextStyle style = new GUITextStyle();
Resource<SpriteFont> font;
string text = "Not set";
Color color;
public T2dSceneObjectWithText() {
font = ResourceManager.Instance.LoadFont("arial12");
}
public string Text { get { return text; } set { text = value; } }
public Color Color { get { return color; } set { color = value; } }
public override void Render(SceneRenderState srs)
{
//DrawUtil.JustifiedText(font, Game.Instance.ConvertFromTorqueUnits(Position), new Vector2(10, 10), TextAlignment.JustifyCenter, color, text);
FontRenderer.Instance.DrawString(font, Game.Instance.ConvertFromTorqueUnits(Position), color, text);
base.Render(srs); }Use this class to create the text and you shoudl also be able to set the layer also. In the code above you can use FontRenderer method or DrawUtil.JustifiedText to draw the text but I have DrawUtil.JustifiedText commented out above.
#8
All GuiControls render on top of scene objects because they are rendered after scene objects. Also, the layer property has no effect on guicontrols as they are rendered in the order they are added to the scenedata.
I tried adding a draw text call to a class derived from sprite but it didn't render anything. Probably a graphics context issue. Apparently there is a TextSprite like object in one of the other gg engines. Don't know why they omitted it in TX.
I have been testing a solution today that seems to work. The pointer part that collides with scene objects is a sprite and the mouse cursor is a GuiBitmap. I have been able to get them to sync up fine so we'll see if any other issues come up. The text button object is a combination between a transparent sprite and a GUIButton. Lots of work! I already have an order-of-magnitude more code then all their demos combined and I'm still just working on the menu system!
05/10/2008 (9:52 pm)
Why "weird"? I want a context sensitive mouse pointer that changes depending on the content it is hovering over. Do you know of a better way to accomplish that?All GuiControls render on top of scene objects because they are rendered after scene objects. Also, the layer property has no effect on guicontrols as they are rendered in the order they are added to the scenedata.
I tried adding a draw text call to a class derived from sprite but it didn't render anything. Probably a graphics context issue. Apparently there is a TextSprite like object in one of the other gg engines. Don't know why they omitted it in TX.
I have been testing a solution today that seems to work. The pointer part that collides with scene objects is a sprite and the mouse cursor is a GuiBitmap. I have been able to get them to sync up fine so we'll see if any other issues come up. The text button object is a combination between a transparent sprite and a GUIButton. Lots of work! I already have an order-of-magnitude more code then all their demos combined and I'm still just working on the menu system!
#9
Thanks!
Sorry about my english..
08/13/2009 (9:57 am)
Hi, Im getting with this code "Material is null". When I inherit from T2DSceneObject instead T2DAnimatedSprite seems that all be fine, but when i change the camera position my SceneObject(in this case a text) is not rendered in some positions of the screen. Can someone help me to figure it out?Thanks!
Sorry about my english..
Torque 3D Owner Will O-Reagan
Modern Intrigues