Game Development Community

How to turn off a single t2dSceneGraph layer? [solved]

by Max Kielland · in Torque Game Builder · 01/24/2013 (5:23 pm) · 3 replies

I have some overlay information that I would like to turn on or off. My thought was to create all the overlay info in the same top layer (let's say layer 0) and then show or hide the overlay information by turning layer 0 on/off.

However, I can't find any command to control the visibility of a single layer.
This overlay is built dynamically and will be updated several times during the game play.

I guess I could create a lot of sprites on layer 0 every time I show the overlay and then clear the layer.
Or use a SimObject to retrieve a list of all objects on a particular layer and iterate through the list to turn them on/off.

#1
01/24/2013 (6:28 pm)
Use a separate scene and display your overlay in front of the game scene. Mich made a resource somewhere, but this thread covers it well enough to get you on the right track.
#2
01/24/2013 (11:53 pm)
The "t2dSceneWindow" has several methods that control which groups and which layers render or not because it acts essentially as a camera so that's why the control is there.

  • SetRenderLayer()
  • SetRenderGroup()
  • SetRenderMask(), getRenderMask(), getRenderLayerMask() & [li]getRenderGroupMask()

If you don't want layer 0 to render then just ensure that its bit is turned off and all others are on.

Hope this helps.
#3
01/25/2013 (5:44 am)
Thanks.
I think the Set/Get RenderMasks is the easiest way to go. I made 3 helper functions to Show or hide a list of layers and leave all other layers unaffected.

The group mask is unaffected but is very simple to implement if needed.
I post the code here for future reference if someone needs it.

//------------------------------------------------------------------------------
// SHOW LAYERS - Max Kielland
// Turn on all layers provided by %layers integer list.
// All other layers and groups are unaffected.
//
function t2dSceneWindow::ShowLayers(%this, %layers) {

  %layerMask = %this.getRenderLayerMask() | List2Mask(%layers);
  %this.setRenderMasks(%layerMask,%this.getRenderGroupMask());
}

//------------------------------------------------------------------------------
// HIDE LAYERS - Max Kielland
// Turn off all layers provided by %layers integer list.
// All other layers and groups are unaffected.
//
function t2dSceneWindow::HideLayers(%this, %layers) {
  
  %layerMask = %this.getRenderLayerMask() & ~List2Mask(%layers);
  %this.setRenderMasks(%layerMask,%this.getRenderGroupMask());
}  

//------------------------------------------------------------------------------
// LIST TO MASK - Max Kielland
// Returns a bit mask (integer) out of a list of integers. Each integer is a bit
// number (not the bit value).
//
function List2Mask(%list) {

  %mask = 0;
  for(%n=0; %n<getWordCount(%list); %n++) {
    %mask |= BIT(getWord(%list,%n));
  }
  return %mask;  
}

To turn on layer 3, 5 and 15 call
sceneWindow2D.ShowLayers("3 5 15");

A good practise is to define "constants" for each layer, such as:

$Constant::Layer_HealthInfo  = 0;
$Constant::Layer_PlayerNames = 3;

Then use concatenation to create the layer list.

sceneWindow2D.HideLayers($Constant::Layer_HealthInfo SPC $Constant::Layer_PlayerNames);

I added a Mask description to TDN with some examples on how to set and clear bits. The TDN documentation of t2dSceneWindow was missing the getRenderLayerMask so I added that one too.