AdvancedSpriteComponent
Declaration
public class Strawberry.Components.AdvancedSpriteComponent
An advanced implementation of the sprite component, which supports keyframe animations.
Inherits: Strawberry.Core.BaseComponent
Properties
Layer
Gets or sets the layer on which the sprite will be drawn.
SpriteLayer Layer { get set }
Transform
Gets the transform component of the owner.
TransformComponent Transform { get }
Origin
Gets the origin of the sprite. It is the same as the origin of the owner's transform component.
Vector2 Origin { get }
Visible
Gets or sets the visibility of the sprite. Default is true.
bool Visible { get set }
Color
Gets or sets the color using which the sprite is drawn. Default is white.
Color Color { get set }
CustomPosition
Vector2 CustomPosition { get set }
DisabledViewports
Gets a list of viewports on which the sprite will not be visible. If empty, it will be visible on all viewports.
List<string> DisabledViewports { get }
CurrentAnimation
Gets or sets the current animation of the sprite.
string CurrentAnimation { get set }
ImageIndex
Gets or sets current frame of the playing animation.
int ImageIndex { get set }
CurrentSprite
Gets the current sprite of the animation. It will change if you change the animation
Sprite CurrentSprite { get }
Methods
OnBegin override
void OnBegin()
OnUpdate override
void OnUpdate()
OnRender override
void OnRender()
AddSprite
Adds an animation key to the component.
void AddSprite(string animationKey, Sprite sprite)
Parameters:
| Name | Type | Description |
|---|---|---|
animationKey |
System.String |
The key of the animation. |
sprite |
Strawberry.Graphics.Sprite |
The sprite to use for the animation. |
Exceptions:
System.ArgumentException—System.ArgumentNullException—
PlayAnimation
Plays an animation by key
void PlayAnimation(string animationKey, bool loop = true)
Parameters:
| Name | Type | Description |
|---|---|---|
animationKey |
System.String |
The key of the animation to play |
loop |
System.Boolean = true |
Indicates whether the animation should loop. Default is true |
Exceptions:
System.Collections.Generic.KeyNotFoundException— If the animation is not found
PlayAnimation
Plays an animation by key using the provided speed (1 = a complete cycle of animation per second)
void PlayAnimation(string animationKey, float speed, bool loop = true)
Parameters:
| Name | Type | Description |
|---|---|---|
animationKey |
System.String |
The key of the animation to play |
speed |
System.Single |
The speed of the animation (1 = a complete cycle of animation per second) |
loop |
System.Boolean = true |
Indicates whether the animation should loop. Default is true |
Exceptions:
System.Collections.Generic.KeyNotFoundException— If the animation is not found
PlayAnimation
Plays an animation by key using the provided speed (1 = a complete cycle of animation per second) and starting at a specific image index
void PlayAnimation(string animationKey, float speed, int imageIndex, bool loop = true)
Parameters:
| Name | Type | Description |
|---|---|---|
animationKey |
System.String |
The key of the animation to play |
speed |
System.Single |
The speed of the animation (1 = a complete cycle of animation per second) |
imageIndex |
System.Int32 |
The starting image index of the animation |
loop |
System.Boolean = true |
Indicates whether the animation should loop. Default is true |
Exceptions:
System.Collections.Generic.KeyNotFoundException— If the animation is not found
ImageIndexOf
Returns the image index of an animation by key
int ImageIndexOf(string animationKey)
Parameters:
| Name | Type | Description |
|---|---|---|
animationKey |
System.String |
The key of the animation |
Returns: The current frame of the animation
ImageCountOf
Returns the total number of frames in an animation by key
int ImageCountOf(string animationKey)
Parameters:
| Name | Type | Description |
|---|---|---|
animationKey |
System.String |
The animation key |
Returns: The total number of frames in the animation
SetAnimationSpeed
Sets the playing speed of current playing animation (1 = a complete cycle of animation per second)
void SetAnimationSpeed(float speed)
Parameters:
| Name | Type | Description |
|---|---|---|
speed |
System.Single |
The new playing speed (1 = a complete cycle of animation per second) |
SetLoop
Sets whether the current playing animation should loop or not
void SetLoop(bool loop)
Parameters:
| Name | Type | Description |
|---|---|---|
loop |
System.Boolean |