Skip to content

GraphicsAPI reference

Class SpriteAtlas

Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics2D.dll
Guide: Graphics

Named sprites packed into one texture, built by Build. The atlas owns the texture: dispose the atlas (usually in Game.Unload) when its sprites are no longer drawn.

C#
public sealed class SpriteAtlas : IDisposable

Inheritance

object ← SpriteAtlas

Implements

IDisposable

Fields

DefaultFrameDuration

The duration of tagged frames whose file gives none, in seconds (a tenth of a second).

C#
public const float DefaultFrameDuration = 0.1

Field Value

float

Properties

Animations

Names of the animations the atlas file tagged (Aseprite frame tags).

C#
public IReadOnlyCollection<string> Animations { get; }

Property Value

IReadOnlyCollection<string>

Names

Names of every sprite in the atlas.

C#
public IReadOnlyCollection<string> Names { get; }

Property Value

IReadOnlyCollection<string>

Texture

The packed texture shared by every sprite of the atlas.

C#
public Texture Texture { get; }

Property Value

Texture

this[string]

The sprite named name.

C#
public Sprite this[string name] { get; }

Property Value

Sprite

Exceptions

KeyNotFoundException

No sprite has that name; check with Contains.

Methods

Clip(string, bool)

The clip of the frame tag name, with each frame’s duration from the file and its direction (forward, reverse, ping-pong) applied. Built once per tag and loop setting, then shared.

C#
public AnimationClip Clip(string name, bool loop = true)

Parameters

name string

loop bool

Returns

AnimationClip

Exceptions

KeyNotFoundException

The atlas has no tag of that name.

Clip(string, float, bool)

A clip of the numbered frames “name0”, “name1”… (or “name1”, “name2”… when the numbering starts at 1, as many packs do) at framesPerSecond.

C#
public AnimationClip Clip(string name, float framesPerSecond, bool loop = true)

Parameters

name string

framesPerSecond float

loop bool

Returns

AnimationClip

Exceptions

KeyNotFoundException

No frames have that name.

Contains(string)

Whether a sprite named name exists.

C#
public bool Contains(string name)

Parameters

name string

Returns

bool

Create(Texture, AtlasData, bool)

Makes an atlas from texture and the frames a packing tool described in data.

C#
public static SpriteAtlas Create(Texture texture, AtlasData data, bool ownsTexture = true)

Parameters

texture Texture

The atlas image as a texture.

data AtlasData

The frames and tags (Parse).

ownsTexture bool

Whether disposing the atlas disposes the texture (true by default).

Returns

SpriteAtlas

Exceptions

InvalidDataException

A frame lies outside the texture, or two frames share a name.

Dispose()

Disposes the texture (unless the atlas was created with ownsTexture: false); sprites of this atlas must not be drawn afterwards.

C#
public void Dispose()

Frames(string)

The “name0”..“nameN” frames added through AddFrames, in order; a numbering that starts at 1 (“walk1”, “walk2”… as in many packs) works too. Collected once per name and shared, read-only: it can be called every frame.

C#
public IReadOnlyList<Sprite> Frames(string name)

Parameters

name string

Returns

IReadOnlyList<Sprite>

Exceptions

KeyNotFoundException

No sprite is named name followed by 0 or 1.

Load(IGraphicsDevice, string, AtlasOptions?, TextureFilter?, string?)

Loads an atlas made by a packing tool: its JSON or XML file and the image it names (next to the file), or imagePath. The atlas owns the texture.

C#
public static SpriteAtlas Load(IGraphicsDevice device, string path, AtlasOptions? options = null, TextureFilter? filter = null, string? imagePath = null)

Parameters

device IGraphicsDevice

Creates the texture.

path string

The atlas file (TexturePacker or Aseprite JSON, Starling XML).

options AtlasOptions?

Default pivot and naming; null for Default.

filter TextureFilter?

The texture’s filter; null for the device’s default.

imagePath string?

The image, when the file names none or names it wrongly; null to use the file’s.

Returns

SpriteAtlas

Exceptions

FileNotFoundException

The atlas file or its image does not exist.

InvalidDataException

The file is not an atlas, or does not fit its image; the message names the file.