VEGO-Engine  0.1
Loading...
Searching...
No Matches
SpriteComponent Class Reference

SpriteComponent class to handle sprite rendering and animation of entities. More...

#include <SpriteComponent.h>

Public Member Functions

 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)
 

Detailed Description

SpriteComponent class to handle sprite rendering and animation of entities.

Constructor & Destructor Documentation

◆ SpriteComponent() [1/3]

SpriteComponent::SpriteComponent ( Textures texture,
int zIndex,
int xOffset = 0,
int yOffset = 0 )
Parameters
textureThe texture to be used for the sprite, must be a Texture enum
xOffsetThe x offset of the sprite relative to the transform component position, used for rendering position
yOffsetThe y offset of the sprite relative to the transform component position, used for rendering position
zIndexThe 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
pathThe path to the texture to be used for the entity (for performance reasons, prefer enums instead)
xOffsetThe x offset of the sprite relative to the transform component position, used for rendering position
yOffsetThe y offset of the sprite relative to the transform component position, used for rendering position
zIndexThe 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
textureThe texture to be used for the sprite, must be a Texture enum
isAnimatedWhether the sprite is animated or not
animationListThe list of animations to be used for the sprite (list of maps mapping a string to an Animation struct)
defaultAnimationThe default animation to be used for the sprite when it first gets loaded
zIndexThe 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
xOffsetThe x offset of the sprite relative to the transform component position, used for rendering position
yOffsetThe 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

Member Function Documentation

◆ playAnimation()

void SpriteComponent::playAnimation ( std::string type)

By name select which animation should be played (gets looped)

Parameters
typename previously set to an animation in animationList

The documentation for this class was generated from the following files: