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

# TextureScale

### Introduction

The TextureScale property can be used to size a Sprite according to its Texture and texture coordiantes. If a Sprite which is displaying its full texture is using a TextureScale of 1, then the Sprite's width will match its Texture's width, and the Sprite's height will match the Texture's Height. A TextureScale of 1 is the most common value, and this is the default for Sprites created in a 2D Entity in the FlatRedBall Editor. TextureScale works by changing a Sprite's Width and Height properties according to a Sprite's Texture and texture coordinate values. Therefore, whenever a Sprite's Texture or texture coordinates change, the Sprite's Width or Height may change if the Sprite is using a TextureScale. If TextureScale of 0, the Sprite will ignore this value and use its existing Width and Height values instead.

### When does TextureScale change Width and Height values values?

The TextureScale value changes the Width and Height values according to the Texture size. The Width and Height of a Sprite will change when the following occur (assuming TextureScale greater than 0):

* Setting TextureScale
* Setting Texture
* Setting [LeftTextureCoordinate](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), [RightTextureCoordinate](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), [TopTextureCoordinate](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), [BottomTextureCoordinate](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* When an animation frame changes (if the Sprite is using AnimationChains)

#### TextureScale can overwrite Scale/Width/Height values

Whenever TextureScale is not 0, it will overwrite Width/Height values when any of the values mentioned above change. For example:

```
// assuming mySprite is a valid Sprite
mySprite.TextureScale = 1f;
mySprite.Width = 10; // We'll assume this value is different than what is set by TextureScale
mySprite.Texture = SomeTexture; // This will reset the Width, overwriting the 10 value
```

### Code Example

The following example creates two Sprites. Their TextureScale is set to the same value. Therefore, their sizes relative to each other is the same as the sizes of their [Textures](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) relative to each other.

```
Sprite ball = SpriteManager.AddSprite("redball.bmp");
ball.TextureScale = 1;
ball.Y = 100;

Sprite logo = SpriteManager.AddSprite(@"Assets\Scenes\frblogo.png");
logo.TextureScale = 1;
logo.Y = 200;
```

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

### TextureScale and Power of Two

Some older video cards cards expect that all textures have a [power of two](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) width and height. In some cases, textures may even be re-sized to fit this requirement. For example, if the current graphics card requires a power of two, an image that is 100X300 may be re-sized to a texture that is 128X512 when loaded in the game. The resizing always increases the resolution of images. This can cause problems if your code uses TextureScale for Sprites which are displaying textures which are not a power of two. The reason is because you may see different behavior on different machines. Using the example above, if you were to load the 100X300 image and display it with a Sprite using a TextureScale of 1, then you would see the following results: *On a machine that doesn't resize:*

```
mySprite.ScaleX will be 50
mySprite.ScaleY will be 150
```

*On a machine that does resize:*

```
mySprite.ScaleX will be 64
mySprite.ScaleY will be 256
```

The solution to this problem is to make sure all of your images have [power of two](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) width and height.

### Animations "resetting" Scale

If you are using an Animation on your Sprite, and you are modifying the scale of your Sprite, then you must do one of two things:

* Change TextureScale instead of Width/Height (or ScaleX/ScaleY)

\-- or --

* Set TextureScale to 0, then manually adjust Width/Height (or ScaleX/ScaleY)

Let's consider an example to see why this is the case. For this example, let's consider a Sprite that is displaying an animation. For simplicity purposes, we'll assume that each frame in the animation is displaying a 32x32 image. So our code may look something like this:

```
Sprite sprite = new Sprite();
SpriteManager.AddSprite(sprite);
// This sets the TextureScale to 1, meaning it will have a width matching its animation frames:
sprite.TextureScale = 1;
// Now, let's force the Width to some value (other than what our animation will have)
sprite.Width = 200;

// Now we'll set the animation:
sprite.AnimationChains = SomeAnimationChainList;
// This will change the texture, meaning that it will immediately change the width
// to the width of the frame:
sprite.CurrentChainName = "AnimationName";
// The Sprite's width will now be the width of the frame instead of 200
```


---

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