Game Development Community

Display a t2d level behind a canvas

by Backman · in Torque Game Builder · 10/18/2008 (12:10 pm) · 4 replies

I'm trying to display a t2d level behind my GUI, but as soon as I load in the GUI the level disappears and the background goes all funny, as it does when no gfx is displayed. How can I do this?

I must be overlooking something very fundemental but just can't figure it out... I'm using Canvas.setContent and that's when it all goes funny.

Cheers.

#1
10/18/2008 (1:45 pm)
In order to display a level, you need these three things:

1. Canvas - This is your actual game window.
2. t2dSceneWindow - This is the GUI conrol that sits in your canvas and paints your scene.
3. t2dSceneGraph - This is attached to your scene window and contains the objects in your scene.

The easiest thing for you to do is add another t2dSceneWindow behind "sceneWindow2d" inside the "mainScreen.gui" file inside "game/gui". Here is a quick sample:

//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(mainScreenGui) {
   canSaveDynamicFields = "0";
   isContainer = "1";
   Profile = "GuiBlackContentProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "640 480";
   MinExtent = "8 8";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";

   new t2dSceneWindow(backgroundSceneWindow) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "640 480";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };
   new t2dSceneWindow(sceneWindow2D) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "640 480";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };
};
//--- OBJECT WRITE END ---

To get this, I opened up TGB, then the GUI builder and then the "mainscreen.gui" file. I then copied and pasted the t2dSceneWindow, renamed it and placed it behind the main layer.

The last thing that you need to do is load your level! In your startGame() function (game/gameScripts/game.cs), around where they call "sceneWindow2d.loadLevel(...)", add this:

backgroundSceneWindow.loadLevel("game/data/levels/myBackgroundLevel.t2d");

Let us know how you get on!
#2
10/18/2008 (2:54 pm)
Also, if you're trying to implement a parallax layer to your game, I recommend that you check out the method that I use in the PSK:

tdn.garagegames.com/wiki/TGB/PlatformerStarterKit/Parallax_Layers

It is pretty nifty ;)
#3
10/19/2008 (5:02 am)
Excellent - think your first few lines was really needed for me.. was a bit confused where in the sceneGraph/Window/Canvas world GUIs came into play. But think I'm getting the hang of it now. A sceneWindow's actually a GUI itself..

I am swapping between different GUIs by using Canvas.setContent (main menu, high score etc) but it seems I should maybe just use different sceneWindows and have them all inside the same .gui, swapping visibilities on and off. I noticed a lag when loading a new canvas as well which that'd fix. Or maybe there's some hierarchy visibility stuff which'd be better suited.

Does that seem like something you'd recommend doing?

Nevertheless, think I just passed through a cloud of confusion I should've put behind me long ago.. thanks guys!
#4
10/21/2008 (10:04 pm)
Many scenewindows hiding and unhiding. That's what I'm doing and it seems to work like a charm :)