> For the complete documentation index, see [llms.txt](https://lua2.fatality.win/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lua2.fatality.win/api/instances/draw/managed/texture/animatedtexture.md).

# AnimatedTexture

This type is an animated texture. This texture type only supports animated GIF types, and does not support APNG.

{% hint style="info" %}
This type inherits [`Texture` ](https://lua2.fatality.win/api/instances/draw/managed/texture.md)type. All of its base methods and fields are also available in this type.
{% endhint %}

{% hint style="success" %}
If you pass an unsupported type, it will instead work exactly like [`Texture` ](https://lua2.fatality.win/api/instances/draw/managed/texture.md)type, meaning controlling frames and looping will be meaningless.
{% endhint %}

{% hint style="success" %}
Using this type for texture atlases is possible, although highly unrecommended. It will produce extra texture objects in memory, and overall will be much slower. Instead, it is advised to construct an actual texture atlas, use [`Texture` ](https://lua2.fatality.win/api/instances/draw/managed/texture.md)type, and use texture mapping.
{% endhint %}

## \_\_call﻿ <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Constructor**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Constructs animated texture.

{% hint style="danger" %}
Passing an invalid pointer, a or memory region that is smaller than the size will result in a crash.
{% endhint %}

Arguments

1\. From file.

| Name   | Type     | Description               |
| ------ | -------- | ------------------------- |
| `path` | `string` | Path to the texture file. |

2\. From memory.

| Name   | Type                                                | Description                             |
| ------ | --------------------------------------------------- | --------------------------------------- |
| `data` | [`Ptr`](https://lua2.fatality.win/api/types/ptr.md) | Pointer to texture file data in memory. |
| `sz`   | `int`                                               | Size of the texture file data.          |

Returns

| Type               | Description                |
| ------------------ | -------------------------- |
| `animated_texture` | Animated texture instance. |

Example

```lua
local gif = draw.AnimatedTexture('funny_gif.gif');
```

***

## shouldLoop <a href="#should-loop" id="should-loop"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-2)[^2]

Type: `bool`

If set to `false`, will not loop the animation automatically. Defaults to `true`.

***

## ResetLoop

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Reset loop to run from the first frame.

**Arguments**

None.

**Returns**

Nothing.

**Example**

```lua
gif:ResetLoop();
```

***

## SetFrame <a href="#set-frame" id="set-frame"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Set a specific frame on the animation. If looping is enabled, will continue the cycle from the passed frame. Otherwise, will display a specific frame of the animation.

{% hint style="info" %}
Frame count starts from `0`.
{% endhint %}

**Arguments**

| Name    | Type  | Description                                          |
| ------- | ----- | ---------------------------------------------------- |
| `frame` | `int` | Frame number. Invalid frame numbers will be clamped. |

**Returns**

Nothing.

**Example**

```lua
gif:SetFrame(5);
```

***

## GetFrameCount <a href="#get-frame-count" id="get-frame-count"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns amount of frames in the animation.

**Arguments**

None.

**Returns**

| Type  | Description  |
| ----- | ------------ |
| `int` | Frame count. |

**Example**

```lua
local frames = gif:GetFrameCount();
gif:SetFrame(frames - 2); -- set to the last frame
```

[^1]: This is a constructor definition for this type.

[^2]: This field is a regular field that must be accessed using a dot (.)

[^3]: This field is a method and must be invoked using a colon (:)


---

# 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://lua2.fatality.win/api/instances/draw/managed/texture/animatedtexture.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.
