Class SpriteSheet
Define the properties of a spritesheet, which sprites we have in it, and sprite animations.
Inheritance
Namespace: BonEngineSharp.Framework
Assembly: BonEngineSharp.dll
Syntax
public class SpriteSheet : Object
Constructors
SpriteSheet()
Create empty spritesheet.
Declaration
public SpriteSheet()
SpriteSheet(ConfigAsset)
Create the spritesheet from config file.
Declaration
public SpriteSheet(ConfigAsset config)
Parameters
| Type | Name | Description |
|---|---|---|
| ConfigAsset | config | Config asset to load spritesheet from. |
Properties
SpritesCount
How many sprites we have on X and Y axis inside the spritesheet. This defines how we calculate the size and position of a specific sprite in sheet.
Declaration
public PointI SpritesCount { get; set; }
Property Value
| Type | Description |
|---|---|
| PointI |
Methods
AddAnimation(SpriteAnimation)
Add animation to spritesheet. Can override existing keys.
Declaration
public void AddAnimation(SpriteAnimation animation)
Parameters
| Type | Name | Description |
|---|---|---|
| SpriteAnimation | animation | Animation to set. |
AddBookmark(String, PointI)
Set a new bookmark in spritesheet. Can override existing keys.
Declaration
public void AddBookmark(string bookmarkId, PointI spriteIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | bookmarkId | Bookmark id to set. |
| PointI | spriteIndex | Bookmark index in spritesheet. |
Animate(Sprite, String, ref Double, Double, out Int32, out Boolean, Single)
Animate sprite based on animation id and progress.
Declaration
public void Animate(Sprite sprite, string animation, ref double progress, double deltaTime, out int currStep, out bool didFinish, float sizeFactor = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| Sprite | sprite | Sprite to animate. |
| System.String | animation | Animation id. |
| 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). |
| System.Single | sizeFactor | Set the size of the sprite to be the spritesheet's single sprite size, multiplied by this value. If set to 0, will not change sprite size. |
Animate(Sprite, String, ref Double, Double, Single)
Animate sprite based on animation id and progress.
Declaration
public void Animate(Sprite sprite, string animation, ref double progress, double deltaTime, float sizeFactor = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| Sprite | sprite | Sprite to animate. |
| System.String | animation | Animation id. |
| 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.Single | sizeFactor | Set the size of the sprite to be the spritesheet's single sprite size, multiplied by this value. If set to 0, will not change sprite size. |
ContainsAnimation(String)
Return if spritesheet contains an animation.
Declaration
public bool ContainsAnimation(string animation)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | animation | Animation id to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if animation exists in spritesheet. |
ContainsBookmark(String)
Return if spritesheet contains a bookmark.
Declaration
public bool ContainsBookmark(string bookmark)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | bookmark | Bookmark id to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if bookmark exists in spritesheet. |
GetAnimation(String)
Get animation by id.
Declaration
public SpriteAnimation GetAnimation(string identifier)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | identifier | Animation id to get. |
Returns
| Type | Description |
|---|---|
| SpriteAnimation | Animation instance. |
GetBookmark(String)
Get bookmark value from id.
Declaration
public PointI GetBookmark(string bookmarkId)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | bookmarkId | Bookmark id. |
Returns
| Type | Description |
|---|---|
| PointI | Bookmark value, as index in spritesheet. |
LoadFromConfig(ConfigAsset)
Load spritesheet properties from config asset. Note: this will replace all existing settings.
Declaration
public void LoadFromConfig(ConfigAsset config)
Parameters
| Type | Name | Description |
|---|---|---|
| ConfigAsset | config | Config file to load from. |
Remarks
Config must contain the following section: [general] - sprites_count = how many sprites there are in this spritesheet, format is: "x,y". - animations = list of comma-separated animations found in this spritesheet config. for every animation listed here, you need to also include a section with animation data. check out 'SpriteAnimation' constructor for more info.
[bookmarks] - optional, contains a list of values where every key is a bookmark identifier and value is sprite index "x,y". later, you can use this to set sprites from spritesheet by names. for example: sheet.SetSprite(sprite, "item_sword");
For more info, check out demo_spritesheet.ini in test assets folder.
SetSprite(Sprite, PointI, Single)
Set a sprite's source rectangle from index in spritesheet.
Declaration
public void SetSprite(Sprite sprite, PointI indexInSheet, float sizeFactor = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| Sprite | sprite | Sprite to set. |
| PointI | indexInSheet | Index in spritesheet. |
| System.Single | sizeFactor | Set the size of the sprite to be the spritesheet's single sprite size, multiplied by this value. If set to 0, will not change sprite size. |
SetSprite(Sprite, String, Single)
Set a sprite's source rectangle from bookmark in spritesheet.
Declaration
public void SetSprite(Sprite sprite, string bookmarkId, float sizeFactor = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| Sprite | sprite | Sprite to set. |
| System.String | bookmarkId | Bookmark id to set. |
| System.Single | sizeFactor | Set the size of the sprite to be the spritesheet's single sprite size, multiplied by this value. If set to 0, will not change sprite size. |