> 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/positionedobject/z.md).

# Z

### Introduction

The Z property controls the absolute Z position of an object. On 3D cameras (Orthogonal=false) , the smaller the Z is, the further away from the camera an object will appear. For information on setting Z in the FlatRedBall Editor, see [this page](https://github.com/flatredball/FlatRedBallDocs/tree/main/api/flatredball/positionedobject/broken-reference/README.md).

### Code Example

The following code assumes an empty Screen, and the code is written in CustomInitialize.

```
// First we'll make a wide sprite:
Sprite sprite = SpriteManager.AddSprite("redball.bmp");
sprite.Width = 100;
sprite.Height = 20;
// And it will have a Z value of 0 (which is the default)
sprite.Z = 0;

// Now let's make another Sprite in front of the first Sprite:
Sprite spriteInFront = SpriteManager.AddSprite("redball.bmp");
spriteInFront.Width = 20;
spriteInFront.Height = 100;
// and it will ahve a Z value of 1, which will put it in front:
spriteInFront.Z = 1;
```

![SpriteZ.PNG](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-4e6b1a5749e06538071f9b9a237557cf54aaf597%2Fmigrated_media-SpriteZ.PNG?alt=media)

### Z in 2D

The Z value controls the distance of an object from the Camera. When using a 2D Camera (Orthogonal=true), changing the Z will not make objects get bigger or smaller as they move closer to/away from the Camera. Despite that, the Z value still impacts a few things:

* Objects with a Z value smaller than the Camera's near clip plane (by default 39) will not be drawn
* Objects with a Z value larger than the Camera's far clip plane (by default -960) will not be drawn
* Objects will sort with each other according to their Z values (excluding shapes like Circle and AxisAlignedRectangle)

### Default values

* SpriteManager.Camera.Z = 40
* New PositionedObject.Z = 0

### Z and Sorting

For information about how Z affects sorting, see the [SpriteManager.OrderedSortType property](/flatredball/api/flatredball/spritemanager/orderedsprites.md) documents.


---

# 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/positionedobject/z.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.
