> 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/camera/setbordersatz.md).

# SetBordersAtZ

### Introduction

As explained in [this tutorial](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) the Camera's X and Y position are the center of the screen (unless the Camera is rotated). Therefore, to keep the Camera from viewing outside of a specific area, the visible width and height must be calculated. In other words, if the Camera should not be able to see anything to the left of X = 0, then the width of the Camera needs to be calculated, and the actual minimum X becomes

```
0 + cameraWidthAtSomeZ/2.0f;
```

The SetBordersAtZ simplifies this process by doing the calculation of cameraWidthAtSomeZ automatically, and even updating mins and maxes if the Camera moves along the Z axis. The SetBordersAtZ sets the following Camera properties:

* MinimumX
* MinimumY
* MaximumX
* MaximumY

The SetBordersAtZ calculates what the minimum and maximum values need to be set at to keep the first four argument values as the visible borders at the Z value passed (fifth argument).

### Code Example

The following code prevents the user from viewing behind +/- 40 on the X and Y axes. Note that bounds will be exceeded if the field of view or aspect ratio is too large for the argument values. The [Keyboard](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) moves the Camera so the bounds can be tested. Add the following using statements:

```
using FlatRedBall.Input;
```

Add the following to Initialize after initializing FlatRedBall:

```
float minimumX = -40;
float minimumY = -40;
float maximumX = 40;
float maximumY = 40;
float zToSetAt = 0;

SpriteManager.Camera.SetBordersAtZ(minimumX, minimumY, maximumX, maximumY, zToSetAt);

// Add a Sprite so the bounds can be visibly tested
Sprite sprite = SpriteManager.AddSprite("redball.bmp");
sprite.ScaleX = 40;
sprite.ScaleY = 40;
```

Add the following to Update:

```
// Use the arrow keys to move the Camera
InputManager.Keyboard.ControlPositionedObject(SpriteManager.Camera);
```

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


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/camera/setbordersatz.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
