Class SpriteAnimation
Represent an animation inside a spritesheet.
Inheritance
Namespace: BonEngineSharp.Framework
Assembly: BonEngineSharp.dll
Syntax
public class SpriteAnimation : Object
Constructors
SpriteAnimation(String)
Create empty sprite animation.
Declaration
public SpriteAnimation(string identifier)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | identifier | Animation identifier. |
SpriteAnimation(String, ConfigAsset)
Load animation from config asset, based on animation identifier.
Declaration
public SpriteAnimation(string identifier, ConfigAsset config)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | identifier | Animation identifier. |
| ConfigAsset | config | Config asset to load from. |
Remarks
Config must contain a section called 'anim_xxx', where xxx is this animation's unique identifier. Under this section, we should have the following keys: - repeats = true / false - does this animation loops, or remain stuck on last step after done? - steps_count = how many steps we have in this animation. - setp_x_duration [x is step index] = duration, in seconds, of this animation step. - setp_x_source [x is step index] = index in spritesheet file, format is: "x,y". - step_x_tag [x is step index] = optional tag to attach to this step. For more info, check out demo_spritesheet.ini in test assets folder.
Properties
Duration
Get animation duration.
Declaration
public float Duration { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Identifier
Animation identifier.
Declaration
public string Identifier { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Repeats
Is this animation repeating itself when done? Or just remain stuck on last frame?
Declaration
public bool Repeats { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
StepsCount
Get animation steps count.
Declaration
public int StepsCount { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
AddStep(SpriteAnimationStep)
Add step to animation.
Declaration
public void AddStep(SpriteAnimationStep step)
Parameters
| Type | Name | Description |
|---|---|---|
| SpriteAnimationStep | step | Step to add. |
Animate(ref Double, Double)
Animate based on progress and return index in spritesheet.
Declaration
public PointI Animate(ref double progress, double deltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | progress | Animation total progress, in seconds. This param is updated every call so you need to preserve it between calls. |
| System.Double | deltaTime | How much to advance animation in current call. |
Returns
| Type | Description |
|---|---|
| PointI | Index to set in spritesheet. |
Animate(ref Double, Double, out Int32, out Boolean)
Animate based on progress and return index in spritesheet.
Declaration
public PointI Animate(ref double progress, double deltaTime, out int currStep, out bool didFinish)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | progress | Animation total progress, in seconds. This param is updated every call so you need to preserve it between calls. |
| System.Double | deltaTime | How much to advance animation in current call. |
| System.Int32 | currStep | Will contain current animation step index. |
| System.Boolean | didFinish | Will be set to true if animation ended (for repeating animations, will be true during the frame it reset back to step 0). |
Returns
| Type | Description |
|---|---|
| PointI | Index to set in spritesheet. |
GetTag(Int32)
Get step tag.
Declaration
public string GetTag(int stepIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | stepIndex | Step index to get tag from. |
Returns
| Type | Description |
|---|---|
| System.String | Step tag or null if not set. |