---
url: /api/kiln/classes/SpriteAnimation.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / SpriteAnimation

# Class: SpriteAnimation

A sprite entity's animation: the shared controller (`set`, `trigger`, `play`, `state`, `time`)
plus the sheet, the shown `frame` (sheet frame number), `clipFrame` (index within the clip),
and `flipX`. Made by `spriteAnimator(sheet, options)`.

## Extends

* [`AnimationController`](AnimationController.md)

## Constructors

### Constructor

```ts
new SpriteAnimation(sheet?, options?): SpriteAnimation;
```

#### Parameters

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `sheet` | [`SpriteSheet`](../interfaces/SpriteSheet.md) | `null` | `null` |
| `options` | [`SpriteAnimatorOptions`](../interfaces/SpriteAnimatorOptions.md) | `{}` |

#### Returns

`SpriteAnimation`

#### Overrides

[`AnimationController`](AnimationController.md).[`constructor`](AnimationController.md#constructor)

## Properties

### graph

```ts
graph: AnimationGraph | null;
```

#### Inherited from

[`AnimationController`](AnimationController.md).[`graph`](AnimationController.md#graph)

***

### state

```ts
state: string = '';
```

The current state's name ('' until the clips are known).

#### Inherited from

[`AnimationController`](AnimationController.md).[`state`](AnimationController.md#state)

***

### time

```ts
time: number = 0;
```

Seconds of clip time since the state was entered (keeps growing across loops).

#### Inherited from

[`AnimationController`](AnimationController.md).[`time`](AnimationController.md#time)

***

### speed

```ts
speed: number = 1;
```

Playback rate for the whole animator, multiplied with each state's speed.

#### Inherited from

[`AnimationController`](AnimationController.md).[`speed`](AnimationController.md#speed)

***

### paused

```ts
paused: boolean = false;
```

Holds the playhead (events and transitions wait too).

#### Inherited from

[`AnimationController`](AnimationController.md).[`paused`](AnimationController.md#paused)

***

### params

```ts
readonly params: Record<string, number | boolean> = {};
```

Parameter values; write them with set().

#### Inherited from

[`AnimationController`](AnimationController.md).[`params`](AnimationController.md#params)

***

### triggers

```ts
readonly triggers: Set<string>;
```

Triggers set since the last animation step.

#### Inherited from

[`AnimationController`](AnimationController.md).[`triggers`](AnimationController.md#triggers)

***

### fade

```ts
fade: Fade | null = null;
```

The crossfade in progress, or null.

#### Inherited from

[`AnimationController`](AnimationController.md).[`fade`](AnimationController.md#fade)

***

### request

```ts
protected request: 
  | {
  state: string;
  fade: number | undefined;
  restart: boolean;
}
  | null = null;
```

play() requests, applied at the start of the next animation step.

#### Inherited from

[`AnimationController`](AnimationController.md).[`request`](AnimationController.md#request)

***

### startState

```ts
protected startState: string | null;
```

The state to enter first, overriding the graph's initial state.

#### Inherited from

[`AnimationController`](AnimationController.md).[`startState`](AnimationController.md#startstate)

***

### sheet

```ts
sheet: SpriteSheet | null;
```

***

### frame

```ts
frame: number = -1;
```

The sheet frame on screen.

***

### clipFrame

```ts
clipFrame: number = 0;
```

The frame's index within the current clip.

***

### flipX

```ts
flipX: boolean;
```

***

### mesh

```ts
mesh: 
  | Mesh<BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>, Material<MaterialEventMap> | Material<MaterialEventMap>[], Object3DEventMap>
  | null = null;
```

The quad the plugin made (its MeshRef).

***

### shown

```ts
shown: object;
```

What the UVs were last written for.

#### frame

```ts
frame: number = -1;
```

#### flipX

```ts
flipX: boolean = false;
```

#### texW

```ts
texW: number = 0;
```

#### texH

```ts
texH: number = 0;
```

## Accessors

### stateSpec

#### Get Signature

```ts
get stateSpec(): AnimationStateSpec | undefined;
```

The current state's spec.

##### Returns

[`AnimationStateSpec`](../interfaces/AnimationStateSpec.md) | `undefined`

#### Inherited from

[`AnimationController`](AnimationController.md).[`stateSpec`](AnimationController.md#statespec)

***

### clip

#### Get Signature

```ts
get clip(): string;
```

The current state's clip name.

##### Returns

`string`

#### Inherited from

[`AnimationController`](AnimationController.md).[`clip`](AnimationController.md#clip)

***

### loop

#### Get Signature

```ts
get loop(): LoopMode;
```

The current state's loop mode.

##### Returns

[`LoopMode`](../type-aliases/LoopMode.md)

#### Inherited from

[`AnimationController`](AnimationController.md).[`loop`](AnimationController.md#loop)

***

### normalizedTime

#### Get Signature

```ts
get normalizedTime(): number;
```

Plays of the current clip so far: 0..1 through the first, 1 at the end of a 'once' clip, 2.5 halfway through a third loop.

##### Returns

`number`

#### Inherited from

[`AnimationController`](AnimationController.md).[`normalizedTime`](AnimationController.md#normalizedtime)

***

### finished

#### Get Signature

```ts
get finished(): boolean;
```

A 'once' clip has reached its end.

##### Returns

`boolean`

#### Inherited from

[`AnimationController`](AnimationController.md).[`finished`](AnimationController.md#finished)

***

### weight

#### Get Signature

```ts
get weight(): number;
```

The crossfade weight of the current state: 0 just after a faded transition, 1 when settled.

##### Returns

`number`

#### Inherited from

[`AnimationController`](AnimationController.md).[`weight`](AnimationController.md#weight)

***

### bound

#### Get Signature

```ts
get bound(): boolean;
```

True once the plugin has told the controller about its clips.

##### Returns

`boolean`

#### Inherited from

[`AnimationController`](AnimationController.md).[`bound`](AnimationController.md#bound)

## Methods

### set()

```ts
set(name, value): this;
```

Sets a parameter declared in the graph's params.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `value` | `number` | `boolean` |

#### Returns

`this`

#### Inherited from

[`AnimationController`](AnimationController.md).[`set`](AnimationController.md#set)

***

### get()

```ts
get(name): number | boolean | undefined;
```

A parameter's value.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |

#### Returns

`number` | `boolean` | `undefined`

#### Inherited from

[`AnimationController`](AnimationController.md).[`get`](AnimationController.md#get)

***

### trigger()

```ts
trigger(name): this;
```

Sets a trigger declared in the graph's triggers. It lasts one animation step unless a transition takes it.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |

#### Returns

`this`

#### Inherited from

[`AnimationController`](AnimationController.md).[`trigger`](AnimationController.md#trigger)

***

### play()

```ts
play(state, options?): this;
```

Enters a state at the next animation step, skipping transitions. Already in it: nothing,
unless `restart`. `fade` overrides the graph's crossfade seconds.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `state` | `string` |
| `options` | { `fade?`: `number`; `restart?`: `boolean`; } |
| `options.fade?` | `number` |
| `options.restart?` | `boolean` |

#### Returns

`this`

#### Inherited from

[`AnimationController`](AnimationController.md).[`play`](AnimationController.md#play)

***

### is()

```ts
is(state): boolean;
```

True when the current state is `state`.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `state` | `string` |

#### Returns

`boolean`

#### Inherited from

[`AnimationController`](AnimationController.md).[`is`](AnimationController.md#is)

***

### bind()

```ts
bind(clips, what): void;
```

Called by the plugin when the clips are known. Checks every state's clip exists, then enters the first state.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `clips` | `ReadonlyMap`<`string`, `ClipInfo`> |
| `what` | `string` |

#### Returns

`void`

#### Inherited from

[`AnimationController`](AnimationController.md).[`bind`](AnimationController.md#bind)

***

### clipInfo()

```ts
clipInfo(name): ClipInfo | undefined;
```

Info for a clip by name.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |

#### Returns

`ClipInfo` | `undefined`

#### Inherited from

[`AnimationController`](AnimationController.md).[`clipInfo`](AnimationController.md#clipinfo)

***

### step()

```ts
step(dt, out): void;
```

One animation step of `dt` seconds: play() requests, then transitions, then the playhead and its events.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `dt` | `number` |
| `out` | `AnimationSink` |

#### Returns

`void`

#### Inherited from

[`AnimationController`](AnimationController.md).[`step`](AnimationController.md#step)

***

### toJSON()

```ts
toJSON(): Record<string, unknown>;
```

#### Returns

`Record`<`string`, `unknown`>

#### Overrides

[`AnimationController`](AnimationController.md).[`toJSON`](AnimationController.md#tojson)
