> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/graphics/layer/sorttype.md).

# SortType

### Introduction

Each Layer can have its own SortType which controls how [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), [Text](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), and [IDrawableBatches](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) sort. This property allows each Layer to have its own Sort type. By default objects on Layers will be sorted by their Z values - objects with smaller Z values (which are in the distance) will draw behind objects which have larger Z values (which are closer to the Camera).

### General information

For general information abou tthe SortTypes property, see the [SpriteManager's OrderedSortType property article](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). This article will discuss how sorting can be modified. Keep in mind that the SpriteManager article linked here discusses object sorting and uses the SpriteManager's OrderedSortType property which only controls how **unlayered objects** sort. In other words, changing the SpriteManager's OrderedSortType will not impact how Layers sort. Unlayered objects can sort differently than Layered objects, and each Layer can specify its own SortType.

### Layer SortType and Camera rotation

If a Camera is unrotated, then the default SortType (Z) will work well. However, if your game uses a camera which can be rotated, then the default SortType may no longer produce desired results. For example, in a typical 3D game the Camera can face in any direction. When this occurs, objects with larger Z values are not guaranteed to be closer to the Camera than objects with smaller Z values. This is very noticeable when working with UI elements which are attached to the Camera. This is the main reason for the DistanceAlongForwardVector SortType. In most you can resolve ordering issues on UI/HUD elements which are attached to a rotated Camera by setting the Layer's SortType to DistanceAlongForwardVector:

```
UiLayer.SortType = SortType.DistanceAlongForwardVector;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/graphics/layer/sorttype.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
