# Sprite

Class · extends [`EventHandler`](https://api.playcanvas.com/engine/classes/EventHandler.md) · category: Graphics

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/scene/sprite.js#L33

A Sprite contains references to one or more frames of a [TextureAtlas](https://api.playcanvas.com/engine/classes/TextureAtlas.md). It can be used by
the [SpriteComponent](https://api.playcanvas.com/engine/classes/SpriteComponent.md) or the [ElementComponent](https://api.playcanvas.com/engine/classes/ElementComponent.md) to render a single frame or a sprite
animation.

## Constructors

### constructor

```ts
new Sprite(device: GraphicsDevice, options?: object)
```

Create a new Sprite instance.

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device of the application.
- `options` (`object`, optional): Options for creating the Sprite.
    - `options.atlas` ([`TextureAtlas`](https://api.playcanvas.com/engine/classes/TextureAtlas.md), optional): The texture atlas. Defaults to null.
    - `options.frameKeys` (`string[]`, optional): The keys of the frames in the sprite atlas that this
      sprite is using. Defaults to null.
    - `options.pixelsPerUnit` (`number`, optional): The number of pixels that map to one PlayCanvas
      unit. Defaults to 1.
    - `options.renderMode` (`number`, optional): The rendering mode of the sprite. Can be:

      - [SPRITE_RENDERMODE_SIMPLE](https://api.playcanvas.com/engine/variables/SPRITE_RENDERMODE_SIMPLE.md)
      - [SPRITE_RENDERMODE_SLICED](https://api.playcanvas.com/engine/variables/SPRITE_RENDERMODE_SLICED.md)
      - [SPRITE_RENDERMODE_TILED](https://api.playcanvas.com/engine/variables/SPRITE_RENDERMODE_TILED.md)

      Defaults to [SPRITE_RENDERMODE_SIMPLE](https://api.playcanvas.com/engine/variables/SPRITE_RENDERMODE_SIMPLE.md).

## Accessors

### atlas

```ts
get atlas(): TextureAtlas
set atlas(value: TextureAtlas)
```

Gets the texture atlas.

### frameKeys

```ts
get frameKeys(): string[]
set frameKeys(value: string[])
```

Gets the keys of the frames in the sprite atlas that this sprite is using.

### meshes

```ts
get meshes(): Mesh[]
```

An array that contains a mesh for each frame.

### pixelsPerUnit

```ts
get pixelsPerUnit(): number
set pixelsPerUnit(value: number)
```

Gets the number of pixels that map to one PlayCanvas unit.

### renderMode

```ts
get renderMode(): number
set renderMode(value: number)
```

Sets the rendering mode of the sprite.

## Methods

### destroy

```ts
destroy(): void
```

Free up the meshes created by the sprite.

## Inherited from [EventHandler](https://api.playcanvas.com/engine/classes/EventHandler.md)

- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
