The DestinationRectangle can be used to make a Layer only draw to part of a Screen. This is often referred to as "masking" or "creating a mask". The DestinationRectangle property in Glue functions the same as in code. For a technical discussion on destination rectangles for Layers, see this page.
The DestinationRectangle can control the area of the screen where a Layer is drawn. By default the DestinationRectangle is blank in Glue, meaning that the Layer will occupy the same area on screen as the main Camera.
This destination rectangle can be changed in Glue. To do this:
Right-click on "DestinationRectnagle" in Glue.
An option for "Use Custom Rectangle" should appear
Select this option and the Layer will be given a custom rectangle:
Now that the DestinationRectangle value is there, we can modify it easily by changing one of the four values, or by expanding the DestinationRectangle and modifying each value independently:
Consider a Sprite which takes up nearly the entire screen:
If this Sprite were put on the Layer, it would look like this:
Layers are a type of object which can be used to control the order in which visible objects in FlatRedBall are drawn. Most objects sort by their Z value. In other words, objects which are further from the Camera will draw behind objects which are closer to the Camera. Layers allow control over draw order without changing the Z of objects.
Layers are often used to draw certain categories of objects. For example, you may have regular game objects (such as trees, the ground, the sky), a Layer specifically for HUD elements (score, health, ammo), and another Layer for popup screens (pause screen, disconnected controller screen). Layers can also be used to draw visuals in 2D coordinates on top of a 3D Camera.
For a general tutorial on Layers in Glue, see the Using Layers Glue Tutorial page. For information on using Layers in code, see the Layer page.
To create a Layer in the FRB Editor:
Select a Screen or Entity which will contain the Layer. Usually Layers are added to Screens.
Click the Quick Actions tab
Click the Add Object button
Select Layer
Click OK
Layers are drawn in the same order that they are added in code. In other words, if Layer1 was added first, then Layer2, Layer1 would draw first, then Layer2 would be drawn on top of Layer1. Similarly, the order of Layers in Glue impacts the order that they are drawn. Layers draw top-to-bottom. Therefore, the first layer when looking at the list of elements in Glue will be drawn first, and any subsequent Layers will be drawn on top.
You can adjust the order of layers by right-clicking on a Layer and selecting one of the options to move it:
To add an object to a layer:
Make sure you have a Layer in the same Screen as your object
Drag+drop the object onto the layer
You can verify that the layer was changed by looking at the LayerOn property. Entity instances can be moved to a layer in code using the MoveToLayer function.
The Is2D option can be used to make a Layer use 2D coordinates. Layers which are 2D can be used even if the current Camera is in 3D. Layers which are 2D are often used to create HUDs and UI Screens.
For information on how to use Layers in code, see the Layer reference page.
The most common usage of the Is2D property is to create a 2D layer in a game which uses a 3D camera. Typically 3D games will have some type of 2D hud, so a 2D layer is needed to hold hud.
This example shows a simple setup where a 2D layer can be used on a 3D graphic. First, the game is set up to use a 3D camera.
Next, a Sprite is added to a GameScreen. It has the following variable values:
Texture = GroundTexture
Right Texture Pixel = 512
BottomTexturePixel = 512
Texture Address Mode = Wrap
Y = -10
Rotation X = 1.5708
The GameScreen has a layer named Layer2D for 2D objects.
Finally the GameScreen has a Text instance called GameOverText which has been placed on Layer2D.
The result is SpriteInstance is drawn in 3D, but the GameOverText is drawn and positioned in 2D.