Game Development Community

GUISceneView and default txscene scene graph - [SOLVED]

by Jake Davis · in Torque X 2D · 08/10/2009 (8:35 am) · 4 replies

I've gone through Jason's GUI tutorial and it was great help. I'm still having trouble getting the following to work: I am creating a project from the default 2D template and using the builder to create the txscene file. I update the XML to include a new GUIStyle and then add a GUISceneView control like you did in the example. The only difference being that I set the scenegraph to the one that was already there from the builder. I then add a text control as a child of the GUISceneView, hoping to get the text to overlay on top of my scene.

<GUIStyle name="gsvs" />
    <GUITextStyle name="TextStyle">
      <FontType>Arial22</FontType>
      <TextColors>
        <Color>
          <X>1</X>
          <Y>1</Y>
          <Z>0</Z>
          <W>1</W>
        </Color>
      </TextColors>
      <SizeToText>true</SizeToText>
    </GUITextStyle>

    <GUISceneView name="gsv">
      <Style nameRef="gsvs"/>
      <SceneGraph nameRef="DefaultSceneGraph"/>
      <Camera nameRef="Camera"/>
      <Position>
        <X>0</X>
        <Y>0</Y>
      </Position>
      <Size>
        <X>128</X>
        <Y>72</Y>
      </Size>
      <ChildControls>
        <GUIText name="TestText">
          <Style nameRef="TextStyle"/>
          <Text>Test Text</Text>
          <Position>
            <X>0</X>
            <Y>0</Y>
          </Position>
          <HorizSizing>Left</HorizSizing>
          <VertSizing>Top</VertSizing>
        </GUIText>
      </ChildControls>
    </GUISceneView>

    <T2DSceneGraph name="DefaultSceneGraph">
      <LayerSortDictionary>
        <SortModes>
          <SortMode>
            <Layer>0</Layer>
            <Comparer valueOf="GarageGames.Torque.T2D.T2DLayerSortDictionary.YAxisSort" />
          </SortMode>
        </SortModes>
      </LayerSortDictionary>
      <T2DSceneContainer>
        <BinSize>20</BinSize>
        <BinCount>256</BinCount>
      </T2DSceneContainer>
    </T2DSceneGraph

The problem is that I can't get my scene view that I declared in XML to load. When I try SetContentControl my scene loads - but no text overlayed - this is the same as if I never called SetContentControl though. When I step through, and try to access the sceneview using FindObject<GUISceneview>("gsv") in code, it returns null...seems like the scene loader isn't loading the sceneview.

SceneLoader.Load(@"datalevelslevelData.txscene");
GUICanvas.Instance.SetContentControl("gsv");

#1
08/13/2009 (4:34 am)
This looks "mostly right." You must have missed some of the elements, though. For example, where's the:

<?xml version="1.0" encoding="utf-8" ?>
<TorqueSceneData>
  <Version>1.0</Version>
  <SceneData>

before the first element? Without that, you will fail to parse. If you fail to parse, then none of your objects will be created, as it sounds like you are seeing.

#2
08/13/2009 (5:35 am)
Jason, I had simply copied in the relevant elements into my post to illustrate what I was trying to add to my xml. Those were added to a txscene file that has all of the other elements such as TorqueSceneData etc.

#3
08/13/2009 (6:59 am)
I'm not sure what I did, but I started over and added elements back to my txscene file. This time it worked. I simply added my GUISceneView as my root control and the Style to go with it. Set it to reference my camera and default scencegraph and it worked.
#4
08/13/2009 (7:06 am)
Also, for those that are interested, you can add all of your GUI controls in a separate XML file and you can then have the SceneView control in your GUI.xml reference the camera and scenegraph in a seperate txscene file. The important thing to remember is to load your GUI.xml after you load your scene with the camera and scenegraph.

SceneLoader.Load(@"data\levels\levelData.txscene"); // scene with camera and scenegraph from the builder
SceneLoader.Load(@"data\GUI\GUI.xml"); // has my GUI scene view and child controls - be sure to load after main scene
            
GUICanvas.Instance.SetContentControl("gsv");

You will want to do this because the TorqueX Builder will remove any gui controls and styles that you manually add to the txscene when you save it from the builder. (only if we had an integrated GUI editor)