xyginext  0.2.0
Second generation of xygine game creation framework
Public Member Functions | List of all members
xy::SpriteSheet Class Referencefinal

Supports loading multiple sprites from a single texture atlas via the ConfigFile format. More...

#include <SpriteSheet.hpp>

Public Member Functions

bool loadFromFile (const std::string &path, TextureResource &rx)
 Attempts to load a ConfigFile from the given path. A reference to a valid texture resource is required to load the sprite sheet texture. More...
 
bool loadFromFile (const std::string &path, ResourceHandler &rx)
 
bool saveToFile (const std::string &path)
 Attempts to save a ConfigFile at the given path. More...
 
Sprite getSprite (const std::string &name) const
 Returns a sprite component with the given name as it appears in the sprite sheet. If the sprite does not exist an empty sprite is returned.
 
void setSprite (const std::string &name, const Sprite &data)
 Set the data of a sprite in the spritesheet. More...
 
void removeSprite (const std::string &name)
 Remove a sprite from the sheet.
 
const std::unordered_map< std::string, Sprite > & getSprites () const
 Returns all sprites in this spritesheet.
 
std::size_t getAnimationIndex (const std::string &name, const std::string &sprite) const
 Returns the index of the animation with the given name on the given sprite if it exists, else returns 0.
 
const std::string & getTexturePath () const
 Returns the path of the texture used by this spritesheet.
 
void setTexturePath (const std::string &path)
 Set the path of the texture used by this spritesheet.
 

Detailed Description

Supports loading multiple sprites from a single texture atlas via the ConfigFile format.

Member Function Documentation

◆ loadFromFile()

bool xy::SpriteSheet::loadFromFile ( const std::string &  path,
TextureResource rx 
)

Attempts to load a ConfigFile from the given path. A reference to a valid texture resource is required to load the sprite sheet texture.

Returns
true if successful, else false

◆ saveToFile()

bool xy::SpriteSheet::saveToFile ( const std::string &  path)

Attempts to save a ConfigFile at the given path.

Returns
true if successful, else false

◆ setSprite()

void xy::SpriteSheet::setSprite ( const std::string &  name,
const Sprite data 
)

Set the data of a sprite in the spritesheet.

Parameters
nameThe name of the sprite to set
dataThe sprite component data to assign
Warning
if sprite already exists it will be overwritten