Render Layers
A render layer is an abstract grouping of objects with similar rendering properties. First and foremost, a render layer has a Z
property for sorting which takes precedence over specific objects Z
property.
This means that if you have a UI render layer which is configured to be in front of a Background render layer, all objects which are associated with the UI layer will always be in front of the objects that are associated
with the background layer, regardless of their Z
property. The Z
property of an object, is therefore used to sort object within the same render layer.
Built in layers
MonoAGS
comes with a few built in layers that are used by default (Background, Foreground, UI and Speech).
Speech Layer
Speech layer is in front to ensure that displayed text can always be seen. This is the default layer used for ICharacter.Say
.
UI Layer
UI layer is next, to ensure that it can always be seen (unless obstructed by text). This is the default layer used for all UI controls.
Foreground Layer
This is followed by the Foreground layer, which is the default for all non UI objects.
Background Layer
And lastly the Background layer, which is the default for the room's background graphics.
You can assign those layers yourself, using AGSLayers
:
cEgo.RenderLayer = AGSLayers.UI; //The player is now on the UI layer!
Additional Layer Properties
In addition to sorting, a render layer offers a few more properties:
Parallax
Each layer can be assigned a ParallaxSpeed
for achieving a parallax effect.
The speed is the factor by which the location is changed based to the normal speed. Giving different speeds for different layers creates the parallax effect which gives the illusion of 3D depth. This is mostly effective in scrolling screens, as the objects move in relation to the camera.
If the room scrolls horizontally (the majority of scrolling rooms), you'd like to change the X
value of the parallax speed.
If the room scrolls vertically (rare but can happen), you'd like to change the Y
value of the parallax speed.
All the default layers have parallax speed of 1 (i.e normal speed), so you'll need to create your own layers to enable the parallax effect.
The closer the object is to the front, the faster it should go, so it should have a bigger parallax speed.
Objects in the foreground should have values larger than 1, and objects in the background should have values smaller than 1.
PointF parallaxSpeed = new PointF (1.4f, 1f); //all objects in this layer will move at a faster horizontal speed than the rest of the objects.
AGSRenderLayer parallaxForegroundLayer = new AGSRenderLayer(-50, parallaxSpeed); //This layer is positioned before the foreground layer and behind the UI layer.
myObjInFront.RenderLayer = parallaxForegroundLayer;
Independent Resolution
You can assign a custom virtual resolution to a layer that will be used for all objects in this layer, which will be different than the default game's virtual resolution. This can be used, for example, if you want specific objects (like characters) at a higher resolution than the background. Note that since the resolution for this layer is different, the coordinate system will be different as well.
For example, let's assume the game resolution is (320,200): The character is using the game's resolution, but the house in the room is in a layer with a (640,400) resolution. This means that if the character's position is (100,100) and the house's position is (200,200) they will actually be drawn in the same location.