Table of Contents

Class Sprite

Namespace
LibGFX.Core.GameElements
Assembly
LibGFX.dll

Represents a sprite

public class Sprite : GameElement, IIdentifier, IPropertyTable, ISerialization
Inheritance
Sprite
Implements
Inherited Members

Constructors

Sprite(string, Vector2, Vector2, SpriteMaterial)

Creates a new sprite

public Sprite(string name, Vector2 position, Vector2 scale, SpriteMaterial material)

Parameters

name string
position Vector2
scale Vector2
material SpriteMaterial

Sprite(string, Vector3, Vector3, SpriteMaterial)

Creates a new sprite

public Sprite(string name, Vector3 position, Vector3 scale, SpriteMaterial material)

Parameters

name string
position Vector3
scale Vector3
material SpriteMaterial

Properties

Animator

The animator of the sprite

public Animator Animator { get; set; }

Property Value

Animator

Bounds2D

The bounds of the sprite in 2D space, computed from its transform and scale.

public Rect Bounds2D { get; }

Property Value

Rect

Color

The color of the sprite

public Vector4 Color { get; set; }

Property Value

Vector4

HasTransparency

Gets a value indicating whether the object uses a material with transparency.

public override bool HasTransparency { get; }

Property Value

bool

Material

The material of the sprite

public SpriteMaterial Material { get; set; }

Property Value

SpriteMaterial

MirrorMode

The mirror mode of the sprite's texture

public TextureMirrorMode MirrorMode { get; set; }

Property Value

TextureMirrorMode

Shader

The shader program used for rendering the sprite

public RenderShader Shader { get; set; }

Property Value

RenderShader

UVScale

The UV scale of the sprite

public Vector2 UVScale { get; set; }

Property Value

Vector2

UVTransform

The UV transform of the sprite

public Vector4 UVTransform { get; set; }

Property Value

Vector4

Methods

AddAnimation(Animation2D)

Adds an animation to the sprite's animator.

public void AddAnimation(Animation2D animation)

Parameters

animation Animation2D

AddAnimationCallback(IAnimationCallback)

Adds an animation callback to the sprite's animator.

public void AddAnimationCallback(IAnimationCallback callback)

Parameters

callback IAnimationCallback

ComputeAABB()

Computes the axis-aligned bounding box (AABB) of the sprite based on its transform.

public override void ComputeAABB()

FindAnimation(string)

Finds an animation by name in the sprite's animator.

public Animation2D FindAnimation(string name)

Parameters

name string

Returns

Animation2D

GetCurrentAnimation()

Gets the current animation from the sprite's animator.

public Animation2D GetCurrentAnimation()

Returns

Animation2D

Init(BaseScene, Viewport, IRenderDevice)

Initializes the sprite

public override void Init(BaseScene scene, Viewport viewport, IRenderDevice renderer)

Parameters

scene BaseScene
viewport Viewport
renderer IRenderDevice

PlayAnimation(string)

Plays an animation by name using the sprite's animator.

public void PlayAnimation(string name)

Parameters

name string

PlayAnimationIfNotCurrent(string)

Plays the specified animation if it is not already the current animation.

public void PlayAnimationIfNotCurrent(string name)

Parameters

name string

The name of the animation to play. Comparison is case-insensitive.

Remarks

If the animator is not set or the specified animation is already playing, this method does nothing.

Render(BaseScene, Viewport, IRenderDevice, Camera)

Renders the sprite

public override void Render(BaseScene scene, Viewport viewport, IRenderDevice renderer, Camera camera)

Parameters

scene BaseScene
viewport Viewport
renderer IRenderDevice
camera Camera

SetAnimationLoop(bool)

Sets whether the animation should loop or not in the sprite's animator.

public void SetAnimationLoop(bool loop)

Parameters

loop bool

SetMirrorMode(TextureMirrorMode)

Sets the mirror mode for the sprite's texture.

public void SetMirrorMode(TextureMirrorMode mode)

Parameters

mode TextureMirrorMode

StopAnimation()

Stops the currently playing animation on the sprite's animator.

public void StopAnimation()

SubImage(float, float, float, float)

Gets an image sub-region from the sprite's texture and sets the UV transform accordingly.

public void SubImage(float x, float y, float width, float height)

Parameters

x float
y float
width float
height float

Update(BaseScene, float)

Updates the sprite

public override void Update(BaseScene scene, float dt)

Parameters

scene BaseScene
dt float