SpriteComponent class to handle sprite rendering and animation of entities.
More...
#include <SpriteComponent.h>
|
| | SpriteComponent (Textures texture, int zIndex, int xOffset=0, int yOffset=0) |
| |
| | SpriteComponent (const char *path, int zIndex, int xOffset=0, int yOffset=0) |
| |
| | SpriteComponent (Textures texture, bool isAnimated, std::map< std::string, std::unique_ptr< Animation > > *animationList, std::string defaultAnimation, int zIndex, int xOffset=0, int yOffset=0) |
| | Constructor used for animated sprites.
|
| |
| void | playAnimation (std::string type) |
| | By name select which animation should be played (gets looped)
|
| |
SpriteComponent class to handle sprite rendering and animation of entities.
◆ SpriteComponent() [1/3]
| SpriteComponent::SpriteComponent |
( |
Textures | texture, |
|
|
int | zIndex, |
|
|
int | xOffset = 0, |
|
|
int | yOffset = 0 ) |
- Parameters
-
| texture | The texture to be used for the sprite, must be a Texture enum |
| xOffset | The x offset of the sprite relative to the transform component position, used for rendering position |
| yOffset | The y offset of the sprite relative to the transform component position, used for rendering position |
| zIndex | The z-index of the sprite, used for rendering order, in order to show up on the map, the zIndex must be higher than the layer you want it to show up on |
◆ SpriteComponent() [2/3]
| SpriteComponent::SpriteComponent |
( |
const char * | path, |
|
|
int | zIndex, |
|
|
int | xOffset = 0, |
|
|
int | yOffset = 0 ) |
- Parameters
-
| path | The path to the texture to be used for the entity (for performance reasons, prefer enums instead) |
| xOffset | The x offset of the sprite relative to the transform component position, used for rendering position |
| yOffset | The y offset of the sprite relative to the transform component position, used for rendering position |
| zIndex | The z-index of the sprite, used for rendering order, in order to show up on the map, the zIndex must be higher than the layer you want it to show up on |
◆ SpriteComponent() [3/3]
| SpriteComponent::SpriteComponent |
( |
Textures | texture, |
|
|
bool | isAnimated, |
|
|
std::map< std::string, std::unique_ptr< Animation > > * | animationList, |
|
|
std::string | defaultAnimation, |
|
|
int | zIndex, |
|
|
int | xOffset = 0, |
|
|
int | yOffset = 0 ) |
Constructor used for animated sprites.
- Parameters
-
| texture | The texture to be used for the sprite, must be a Texture enum |
| isAnimated | Whether the sprite is animated or not |
| animationList | The list of animations to be used for the sprite (list of maps mapping a string to an Animation struct) |
| defaultAnimation | The default animation to be used for the sprite when it first gets loaded |
| zIndex | The z-index of the sprite, used for rendering order, in order to show up on the map, the zIndex must be higher than the layer you want it to show up on |
| xOffset | The x offset of the sprite relative to the transform component position, used for rendering position |
| yOffset | The y offset of the sprite relative to the transform component position, used for rendering position |
How to spritesheet animation:
An animation sprite sheet consists of multiple sprites of the specified size (library supports 32x32) arranged in a grid. Each row of the grid represents one animation, and each column in a row is one frame of the animation. If a sprite sheet contains multiple animations with different frame counts, you can just leave the rest of the row blank. Be aware to specify the correct frame count in the animation struct!
- See also
- Animation
Example of a sprite sheet with 2 animations of 2 frames each
◆ playAnimation()
| void SpriteComponent::playAnimation |
( |
std::string | type | ) |
|
By name select which animation should be played (gets looped)
- Parameters
-
| type | name previously set to an animation in animationList |
The documentation for this class was generated from the following files: