The TopDestination, BottomDestination, LeftDestination, and RightDestination properties of the LayerCameraSettings class allow Layers to render to only a portion of the Screen (also known as creating a mask). These coordinates are measured in pixel units in screen space. In other words, 0 is the left side of the screen for LeftDestination and RightDestination, and it increases to the right. The value of 0 is the top of the screen for TopDestination and BottomDestination, and it increases downward. The destination values are not necessarily used when a given Layer is rendered. The default value for TopDestination, BottomDestination, LeftDestination, and RightDestination is -1. If -1 is used, then the Camera's DestinationRectangle values are used.
The following code creates a LayerCameraSetting which has a 200 pixel border around the edges of the screen. The Layer draws a large Sprite which is masked by the destination values of the LayerCameraSettings. Add the following using statement:
Add the following to Initialize after initializing FlatRedBall:
If you are explicitly setting the destination rectangle of a LayerCameraSettings object, then you may encounter an exception. If FlatRedBall detects that the BottomDestination is too large, you may get an error as follows:
Similarly you may get a message about the width, which might read:
You can fix this in one of the following ways:
Prevent resizing of your game window
Adjust the LayerCameraSettings for your Layer to fit within the bounds of the display
Set the LayerCameraSettings' destination values to -1, which will result it in automatically adjusting to its contained Camera destination.
The LayerCameraSettings class is a class which can be used to override the settings of a FlatRedBall.Camera on a by FlatRedBall.Graphics.Layer basis. LayerCameraSettings can be used to achieve the following:
Adding a 2D layer when the main Camera is 3D
Adding a 3D layer when the main Camera is 2D
Adjusting the field of view on a 3D layer when the Camera is 3D
Adjusting the orthogonal width and height values on a 2D layer when the Camera is 2D
The following code creates a FlatRedBall.Graphics.Layer which renders in 2D even though the camera is rendering in 3D: Add the following using statement:
Add the following to Initialize after initializing FlatRedBall:
If a Layer is added through Glue, the generated code for the layer will instantiate a new LayerCameraSettings and add it to the Layer. By default these settings will match the camera at the time of Layer creation.
The OrthogonalWidth and OrthogonalHeight of a LayerCameraSettings object controls the number of units wide and high that the Layer will display. The LayerCameraSettings' Orthogonal value must be true for the OrthogonalWidth and OrthogonalHeight properties to apply.
This example was initially constructed in Glue. To reproduce this:
Create a Screen
Add a Sprite to the Screen
Create a 2D Layer
Place the Sprite on the 2D Layer
You can match the LayerCameraSettings to match the Camera by setting the OrthogonalWidth/OrthogonalHeight of the LayerCameraSettings to the Camera's OrthogonalWidth/OrthogonalHeight. This assumes that both the Layer and Camera are using orthogonal values.
Orthogonal values can be used to determine the width and height in world coordinates of the area that a Layer displays. Usually these coordinates happen to match the pixel display area as well, but it is possible for this to not be the case if destination rectangle values are set differently from orthogonal values. The following code will size a Sprite so that it is the same size as the displayed area of a Layer:
Set its Texture (I used )
If you run the game you should now see the Sprite rendering on the Layer: We can now zoom in on this Sprite simply by adjusting the orthogonal values on the LayerCameraSettings. Since I'm using Glue I'll add the following code to my CustomInitialize for my Screen that contains the Layer:
Now the Sprite (and anything on the same Layer) will appear at 8x zoom: