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
namestringpositionVector2scaleVector2materialSpriteMaterial
Sprite(string, Vector3, Vector3, SpriteMaterial)
Creates a new sprite
public Sprite(string name, Vector3 position, Vector3 scale, SpriteMaterial material)
Parameters
namestringpositionVector3scaleVector3materialSpriteMaterial
Properties
Animator
The animator of the sprite
public Animator Animator { get; set; }
Property Value
Bounds2D
The bounds of the sprite in 2D space, computed from its transform and scale.
public Rect Bounds2D { get; }
Property Value
Color
The color of the sprite
public Vector4 Color { get; set; }
Property Value
HasTransparency
Gets a value indicating whether the object uses a material with transparency.
public override bool HasTransparency { get; }
Property Value
Material
The material of the sprite
public SpriteMaterial Material { get; set; }
Property Value
MirrorMode
The mirror mode of the sprite's texture
public TextureMirrorMode MirrorMode { get; set; }
Property Value
Shader
The shader program used for rendering the sprite
public RenderShader Shader { get; set; }
Property Value
UVScale
The UV scale of the sprite
public Vector2 UVScale { get; set; }
Property Value
UVTransform
The UV transform of the sprite
public Vector4 UVTransform { get; set; }
Property Value
Methods
AddAnimation(Animation2D)
Adds an animation to the sprite's animator.
public void AddAnimation(Animation2D animation)
Parameters
animationAnimation2D
AddAnimationCallback(IAnimationCallback)
Adds an animation callback to the sprite's animator.
public void AddAnimationCallback(IAnimationCallback callback)
Parameters
callbackIAnimationCallback
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
namestring
Returns
GetCurrentAnimation()
Gets the current animation from the sprite's animator.
public Animation2D GetCurrentAnimation()
Returns
Init(BaseScene, Viewport, IRenderDevice)
Initializes the sprite
public override void Init(BaseScene scene, Viewport viewport, IRenderDevice renderer)
Parameters
sceneBaseSceneviewportViewportrendererIRenderDevice
PlayAnimation(string)
Plays an animation by name using the sprite's animator.
public void PlayAnimation(string name)
Parameters
namestring
PlayAnimationIfNotCurrent(string)
Plays the specified animation if it is not already the current animation.
public void PlayAnimationIfNotCurrent(string name)
Parameters
namestringThe 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
sceneBaseSceneviewportViewportrendererIRenderDevicecameraCamera
SetAnimationLoop(bool)
Sets whether the animation should loop or not in the sprite's animator.
public void SetAnimationLoop(bool loop)
Parameters
loopbool
SetMirrorMode(TextureMirrorMode)
Sets the mirror mode for the sprite's texture.
public void SetMirrorMode(TextureMirrorMode mode)
Parameters
modeTextureMirrorMode
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
Update(BaseScene, float)
Updates the sprite
public override void Update(BaseScene scene, float dt)