dEngine
Simple 2D C++ game engine
Public Member Functions | Private Attributes | List of all members
dengine::SpriteSheet Class Reference

A SpriteSheet. More...

#include <SpriteSheet.h>

Inheritance diagram for dengine::SpriteSheet:
dengine::Component

Public Member Functions

 SpriteSheet (std::string filepath, GameObject &parent)
 Constructor. More...
 
 ~SpriteSheet ()
 Destructor. More...
 
void SetCurrentAnimation (std::string name)
 Set current animation. More...
 
void RegisterAnimation (std::string name, int x, int y, int w, int h, int frames)
 Register new animation. More...
 
void DeregisterAnimation (std::string name)
 Remove animation. More...
 
bool HasAnimation (std::string name)
 Check if spritesheet has an animation. More...
 
void Render () override
 Render the animation. More...
 
void Pause (bool pause)
 
- Public Member Functions inherited from dengine::Component
 Component (GameObject &parent)
 Create a new component for a gameobject. More...
 
virtual void NotifyCollision (GameObject &other)
 
std::string GetName ()
 Returns the component's name. More...
 
virtual void Start ()
 Start the object To be called by the GameObject's Start method. This should be called at the beginning of instantiation. More...
 
virtual void Update ()
 

Private Attributes

std::map< std::string, AnimationanimationCollection
 
SDL_Texture * sheet
 
std::string currentAnimation = ""
 
bool isPaused = false
 

Additional Inherited Members

- Protected Attributes inherited from dengine::Component
GameObjectparent
 
std::string name
 

Detailed Description

A SpriteSheet.

SpriteSheets are used for images that may include multiple depictions or animations, usually based off a single image with many images included. Google "Game Spritesheet" and switch to images to see an example.

Constructor & Destructor Documentation

◆ SpriteSheet()

SpriteSheet::SpriteSheet ( std::string  filepath,
GameObject parent 
)

Constructor.

Create a Spritesheet object

Parameters
filepathFile path to the spritesheet image
parentThe parent object of this spritesheet

◆ ~SpriteSheet()

SpriteSheet::~SpriteSheet ( )

Destructor.

Cleans up and frees resources that were allocated by the spritesheet

Member Function Documentation

◆ DeregisterAnimation()

void SpriteSheet::DeregisterAnimation ( std::string  name)

Remove animation.

Deregisters an animation, freeing up resources and ensuring animation can no longer be called

Parameters
nameName of the animation

◆ HasAnimation()

bool SpriteSheet::HasAnimation ( std::string  name)

Check if spritesheet has an animation.

Determine if a named animation has already been registered

Parameters
nameName of the animation
Returns
Whether the animation exists or not

◆ Pause()

void SpriteSheet::Pause ( bool  pause)

Pauses the rendering of an animation

◆ RegisterAnimation()

void SpriteSheet::RegisterAnimation ( std::string  name,
int  x,
int  y,
int  w,
int  h,
int  frames 
)

Register new animation.

Register an animation from a spritesheet

Parameters
nameName of the animation
xThe starting x postion of the first frame of the animation
yThe starting y position of the first frame of the animation
wThe width of each frame of the animation
hThe height of each frame of the animation
framesThe total number of frames in the animation

◆ Render()

void SpriteSheet::Render ( )
overridevirtual

Render the animation.

Reimplemented from dengine::Component.

◆ SetCurrentAnimation()

void SpriteSheet::SetCurrentAnimation ( std::string  name)

Set current animation.

Set the current animation to be rendered

Parameters
nameThe name of a registered animation

Member Data Documentation

◆ animationCollection

std::map<std::string, Animation> dengine::SpriteSheet::animationCollection
private

◆ currentAnimation

std::string dengine::SpriteSheet::currentAnimation = ""
private

Referenced by Render(), and SetCurrentAnimation().

◆ isPaused

bool dengine::SpriteSheet::isPaused = false
private

Referenced by Pause(), and Render().

◆ sheet

SDL_Texture* dengine::SpriteSheet::sheet
private

Referenced by Render(), SpriteSheet(), and ~SpriteSheet().