Header menu logo Mibo

AnimatedSprite Module

Functions for creating, updating, and drawing animated sprites.

The update and draw functions are aggressively inlined and designed for zero allocations during the game loop.

Functions and values

Function or value Description

create sheet animationName

Full Usage: create sheet animationName

Parameters:
    sheet : SpriteSheet - The sprite sheet containing animations.
    animationName : string - Name of the animation to play initially.

Returns: AnimatedSprite

Create a new animated sprite starting on the specified animation.

sheet : SpriteSheet

The sprite sheet containing animations.

animationName : string

Name of the animation to play initially.

Returns: AnimatedSprite

createWith sheet animationName color scale

Full Usage: createWith sheet animationName color scale

Parameters:
Returns: AnimatedSprite

Create with initial visual properties.

sheet : SpriteSheet
animationName : string
color : Color
scale : float32
Returns: AnimatedSprite

currentSource sprite

Full Usage: currentSource sprite

Parameters:
Returns: Rectangle
Modifiers: inline

Get the current source rectangle for rendering.

sprite : AnimatedSprite
Returns: Rectangle

draw position layer buffer sprite

Full Usage: draw position layer buffer sprite

Parameters:

Draw the sprite at a position using the 2D render buffer.

The sprite is drawn centered on the position with the sheet's origin.

position : Vector2
layer : int<MeasureProduct<RenderLayer, MeasureOne>>
buffer : RenderBuffer<RenderCmd2D>
sprite : AnimatedSprite

drawRect destRect layer buffer sprite

Full Usage: drawRect destRect layer buffer sprite

Parameters:

Draw the sprite at a specific destination rectangle (ignores scale/origin).

Note: Rotation will occur around the top-left corner (Vector2.Zero) of the destination rectangle.

destRect : Rectangle
layer : int<MeasureProduct<RenderLayer, MeasureOne>>
buffer : RenderBuffer<RenderCmd2D>
sprite : AnimatedSprite

drawWithDepth position depth layer buffer sprite

Full Usage: drawWithDepth position depth layer buffer sprite

Parameters:

Draw the sprite with a custom depth value.

position : Vector2
depth : float32
layer : int<MeasureProduct<RenderLayer, MeasureOne>>
buffer : RenderBuffer<RenderCmd2D>
sprite : AnimatedSprite

duration sprite

Full Usage: duration sprite

Parameters:
Returns: float32
Modifiers: inline

Get the total duration of the current animation.

sprite : AnimatedSprite
Returns: float32

facingLeft sprite

Full Usage: facingLeft sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Set facing left (flip X on).

sprite : AnimatedSprite
Returns: AnimatedSprite

facingRight sprite

Full Usage: facingRight sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Set facing right (flip X off).

sprite : AnimatedSprite
Returns: AnimatedSprite

flipX sprite

Full Usage: flipX sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Toggle horizontal flip.

sprite : AnimatedSprite
Returns: AnimatedSprite

flipY sprite

Full Usage: flipY sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Toggle vertical flip.

sprite : AnimatedSprite
Returns: AnimatedSprite

isFinished sprite

Full Usage: isFinished sprite

Parameters:
Returns: bool
Modifiers: inline

Is the current animation finished? (always false for looping animations)

sprite : AnimatedSprite
Returns: bool

isPlaying animName sprite

Full Usage: isPlaying animName sprite

Parameters:
Returns: bool

Is currently playing the specified animation?

animName : string
sprite : AnimatedSprite
Returns: bool

play animationName sprite

Full Usage: play animationName sprite

Parameters:
Returns: AnimatedSprite

Play an animation by name. Does string lookup only when actually changing.

animationName : string
sprite : AnimatedSprite
Returns: AnimatedSprite

playByIndex animIndex sprite

Full Usage: playByIndex animIndex sprite

Parameters:
Returns: AnimatedSprite

Play by animation index (zero string allocation).

For maximum performance, resolve animation names to indices once at load time, then use this function during gameplay.

animIndex : int
sprite : AnimatedSprite
Returns: AnimatedSprite

playIfNot animationName sprite

Full Usage: playIfNot animationName sprite

Parameters:
Returns: AnimatedSprite

Play animation only if not already playing it.

animationName : string
sprite : AnimatedSprite
Returns: AnimatedSprite

restart sprite

Full Usage: restart sprite

Parameters:
Returns: AnimatedSprite

Force restart the current animation from the beginning.

sprite : AnimatedSprite
Returns: AnimatedSprite

toSpriteEffects sprite

Full Usage: toSpriteEffects sprite

Parameters:
Returns: SpriteEffects
Modifiers: inline

Get the MonoGame SpriteEffects for the sprite's current flip state.

sprite : AnimatedSprite
Returns: SpriteEffects

update deltaSeconds sprite

Full Usage: update deltaSeconds sprite

Parameters:
Returns: AnimatedSprite

Advance the animation by delta time.

This function is designed for zero allocations. Call it from your Elmish update function each frame.

deltaSeconds : float32
sprite : AnimatedSprite
Returns: AnimatedSprite

withColor color sprite

Full Usage: withColor color sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Set the tint color.

color : Color
sprite : AnimatedSprite
Returns: AnimatedSprite

withRotation rotation sprite

Full Usage: withRotation rotation sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Set the rotation in radians.

rotation : float32
sprite : AnimatedSprite
Returns: AnimatedSprite

withScale scale sprite

Full Usage: withScale scale sprite

Parameters:
Returns: AnimatedSprite
Modifiers: inline

Set the scale factor.

scale : float32
sprite : AnimatedSprite
Returns: AnimatedSprite

Type something to start searching.