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

# Sprite

### Introduction

The Sprite is a flat graphical object which is commonly used as the visuals for entities and for particles. Sprites can also be used to display tilemaps and UI, although Tiled and Gum provide more flexibility and performance. The Sprite class inherits from the [PositionedObject](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) class.

Sprites are usually created through the FlatRedBall Editor when associated with entities, although Sprites can also be created in code when dynamic visuals are needed.

### Creating a Sprite in Code

In most cases, a Sprite can be created in code by instantiating it, assigning a texture, and adding it to the SpriteManager so that it is drawn. The following code assumes that `TextureFile` is a valid Texture2D:

```csharp
// Creates a new Sprite instance
var sprite = new Sprite();
// Assigns the texture to display. 
sprite.Texture = TextureFile;
// Sets the Sprite's scale so that it renders 1:1 relative to its source Texture
sprite.TextureScale = 1;
// Adds the Sprite to the SpriteManager so that it is shown, and so that it is
// "managed" (velocity, acceleration, and attachments are maintained)
SpriteManager.AddSprite(sprite);
```

Once the Sprite has been created, it will persist until it is removed. If your game does not navigate to other Screens, and if you do not need to remove the Sprite, then no additional code is needed.

If you would like to remove your Sprite, you can call SpriteManager.RemoveSprite:

```csharp
SpriteManager.RemoveSprite(sprite);
```

If you are creating a Sprite that is owned by a FlatRedBall Screen or Entity, then you will need to either:

* Explicitly call RemoveSprite when it is time to destroy the object containing the Sprite (usually `CustomDestroy` )
* Add the Sprite to a PositionedObjectList\<Sprite> created in the FlatRedBall Editor on the container. When the container is removed, then the contents of the sprite list will automatically get removed from the engine.

### Sprite Scale

For information on Scale, see the [IScalable wiki entry](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). To match the on-screen pixel dimensions of a Sprite to its referenced [Texture's](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) pixel dimensions, see the [2D in FlatRedBall tutorial](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### Texture

Sprites can be thought of as picture frames or canvases - they define how big a displayed image will be, its position, its rotation, and so on. However, the image or picture that they display is separate from the Sprite itself. This is an important realization because this often differs from other game engines where the image and the Sprite are one and the same at runtime. For more information, see the [Sprite.Texture](/flatredball/api/flatredball/graphics/animation/flatredball-graphics-animationframe/texture.md) page.

### Color and Alpha

For information on color and alpha operations (blending), see the [IColorable wiki entry](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### Z Buffered Sprites

Using a Z Buffer allows Sprites to properly overlap. For more information, see the [Z Buffered Sprites wiki entry](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### Particle Sprites

Particle Sprites are created through the [SpriteManager](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) just like other Sprites. Particle Sprites are created from a pool of Sprites that is created when the engine is first initiated. The following code creates a particle Sprite:

```
Sprite newSprite = SpriteManager.AddParticleSprite();
```

Particle Sprites have all of the same functionality as regular Sprites - in fact, they are just Sprites. The only difference is that there is minimal memory allocation and garbage collection so they can be useful when creating particle effects. Particle Sprites are used by [Emitters](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

###


---

# 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/sprite.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.
