Sprite class forward declaration. More...
#include <SpriteSheet.h>
Public Types | |
using | Ptr = std::shared_ptr< SpriteSheet > |
shared spritesheet pointer More... | |
using | Frame = UIntRect |
A frame in the spritesheet. More... | |
Public Member Functions | |
SpriteSheet (const std::string &sourceTexture, Vector2u frameSize, Vector2u spacing={0, 0}, UIntRect area={}) | |
Create the spritesheet. More... | |
SpriteSheet (const SpriteSheet &)=default | |
Copy constructor. More... | |
SpriteSheet & | operator= (const SpriteSheet &)=default |
Copy assignment operator. More... | |
SpriteSheet (SpriteSheet &&) noexcept=default | |
Move constructor. More... | |
SpriteSheet & | operator= (SpriteSheet &&) noexcept=default |
Move assignment operator. More... | |
std::string | getClassName () const override |
Get the name of this class. More... | |
Vector2u | getFrameSize () const |
Get the size of each frame in the spritesheet. More... | |
Vector2u | getSpaceBetweenFrames () const |
Get the space between frames in the spritesheet. More... | |
std::size_t | getFramesCount () const |
Get the number of frames in the spritesheet. More... | |
std::optional< Frame > | getFrame (Index index) const |
Get the frame at a given index. More... | |
std::optional< Frame > | getFrame (const std::string &alias) const |
Get the frame by its assigned alias. More... | |
std::vector< Frame > | getFramesOnRow (unsigned int row) const |
Get all the frames in a given row. More... | |
std::vector< Frame > | getFramesOnColumn (unsigned int column) const |
Get all the frames in a given column. More... | |
std::vector< Frame > | getFramesInRange (Index start, Index end) const |
Get all the frames in a range. More... | |
std::vector< Frame > | getAllFrames () const |
Get all the frames in the spritesheet. More... | |
Vector2u | getSizeInFrames () const |
Get the size of the spritesheet in frames. More... | |
unsigned int | getRowCount () const |
Get the number of rows in the spritesheet. More... | |
unsigned int | getColumnCount () const |
Get the number of columns in the spritesheet. More... | |
Sprite | getSprite (Index index) const |
Get a sprite from an index. More... | |
Sprite | getSprite (const std::string &alias) const |
Get a sprite from the index with a given alias. More... | |
std::vector< Sprite > | getSpritesOnRow (unsigned int row) const |
Get all the sprites in a row. More... | |
std::vector< Sprite > | getSpritesOnColumn (unsigned int column) const |
Get all the sprites in a column. More... | |
std::vector< Sprite > | getSpritesInRange (Index start, Index end) const |
Get all the sprites in a range. More... | |
std::vector< Sprite > | getAllSprites () const |
Get all the sprites in the spritesheet. More... | |
bool | hasFrame (Index index) const |
Check if an index has a frame or not. More... | |
bool | hasFrame (const std::string &alias) const |
Check if there is a frame with a specified alias. More... | |
bool | assignAlias (Index index, const std::string &alias) |
Assign an alias to a frame. More... | |
~SpriteSheet () override | |
Destructor. More... | |
Vector2u | getSize () const |
Get the size of the sprite image in pixels. More... | |
unsigned int | getWidth () const |
Get the width of the sprite image in pixels. More... | |
unsigned int | getHeight () const |
Get the height of the sprite image in pixels. More... | |
std::string | getClassType () const override |
Get the name of this class. More... | |
const Texture & | getTexture () const |
Get the source texture of the sprite image. More... | |
Vector2u | getRelativePosition () const |
Get the top-left position of the sprite image relative to the sprite image source texture. More... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the alias of the object. More... | |
unsigned int | getObjectId () const |
Get the id of the object. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback) |
Add an event listener to a specific property change event. More... | |
void | onPropertyChange (const Callback< Property > &callback) |
Add an event listener to a property change event. More... | |
int | onEvent (const std::string &event, const Callback<> &callback) |
Add an event listener to an event. More... | |
bool | unsubscribe (const std::string &event, int id) |
Remove an event listener from an event. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | removeDestructionListener (int id) |
Remove a destruction listener form the object. More... | |
bool | operator== (const Object &rhs) const |
Check if two objects are the same object or not. More... | |
bool | operator!= (const Object &rhs) const |
Check if two objects are not the same object. More... | |
Protected Member Functions | |
bool | contains (Vector2u point) const |
Check if the sprite image contains a point or not. More... | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emit (const std::string &event) |
Dispatch an action event. More... | |
Sprite class forward declaration.
An ImageSprite which contains images of the same size arranged in a grid
This class only works with a SpriteImage that has contiguous textures (perfectly aligned vertically or horizontally) that are the same size. Use the TextureAtlas for textures that are different sizes and have no specific arrangement in the source texture. Usually a spritesheet holds animation frames of a single entity such as (but not limited to) a characters animation in an idle, walking, running or jumping state
Definition at line 52 of file SpriteSheet.h.
using ime::SpriteSheet::Frame = UIntRect |
A frame in the spritesheet.
Definition at line 55 of file SpriteSheet.h.
using ime::SpriteSheet::Ptr = std::shared_ptr<SpriteSheet> |
shared spritesheet pointer
Definition at line 54 of file SpriteSheet.h.
ime::SpriteSheet::SpriteSheet | ( | const std::string & | sourceTexture, |
Vector2u | frameSize, | ||
Vector2u | spacing = {0, 0} , |
||
UIntRect | area = {} |
||
) |
Create the spritesheet.
sourceTexture | Filename of the image used by the spritesheet |
frameSize | The size of each frame in the source texture |
spacing | The space between frames in the source texture |
area | Sub-rectangle to construct spritesheet from |
FileNotFount | if the the source image cannot be found on the disk |
The area can be used to construct the spritesheet from a sub-rectangle of the whole spritesheet image. To construct the spritesheet from the whole image (default), leave the area argument unspecified. If the area rectangle crosses the bounds of the image, it is adjusted to fit the image size
|
default |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
override |
Destructor.
bool ime::SpriteSheet::assignAlias | ( | Index | index, |
const std::string & | alias | ||
) |
Assign an alias to a frame.
index | Index of the frame to assign an alias |
alias | The alias to be assigned to the frame |
This function allows a frame or a sprite to be accessed by its name instead of its index
|
protectedinherited |
Check if the sprite image contains a point or not.
point | The point to be checked |
|
protectedinherited |
Dispatch an action event.
event | The name of the event to be dispatched |
This function will invoke all event listeners of the specified event. The function should be used for events that represent an action, rather than those that represent a property change (Use emitChange for that)
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
std::vector<Frame> ime::SpriteSheet::getAllFrames | ( | ) | const |
Get all the frames in the spritesheet.
std::vector<Sprite> ime::SpriteSheet::getAllSprites | ( | ) | const |
Get all the sprites in the spritesheet.
|
overridevirtual |
|
overridevirtualinherited |
Get the name of this class.
Note that this function is only overridden by child classes of Object which also serve as a base class for other classes
Reimplemented from ime::Object.
unsigned int ime::SpriteSheet::getColumnCount | ( | ) | const |
Get the number of columns in the spritesheet.
std::optional<Frame> ime::SpriteSheet::getFrame | ( | const std::string & | alias | ) | const |
Get the frame by its assigned alias.
alias | The alias assigned to a frame |
Get the frame at a given index.
index | The index to get the frame of |
Note that index starts at {0, 0}
std::size_t ime::SpriteSheet::getFramesCount | ( | ) | const |
Get the number of frames in the spritesheet.
Note that the number of sprites in the spritesheet is the same as the number of frames
Get all the frames in a range.
start | The start of the range (inclusive) |
end | The end of the range (inclusive) |
The range must either be on a row or column. For rows the x components of the start and end arguments must be the same. Similarly, for columns, the y components of the start and end must be the same otherwise an empty vector will be returned. In addition for components that varies (row or column), the start component must be less than the end component. An empty vector will also be returned if the either the start or end index is out of bounds
Note that start and end start at {0, 0}
Vector2u ime::SpriteSheet::getFrameSize | ( | ) | const |
Get the size of each frame in the spritesheet.
std::vector<Frame> ime::SpriteSheet::getFramesOnColumn | ( | unsigned int | column | ) | const |
Get all the frames in a given column.
column | The column to get the frames from |
Note that column starts at 0
std::vector<Frame> ime::SpriteSheet::getFramesOnRow | ( | unsigned int | row | ) | const |
Get all the frames in a given row.
row | The row to get the frames from |
Note that row starts at 0
|
inherited |
Get the height of the sprite image in pixels.
|
inherited |
Get the id of the object.
Each object has a unique id
|
inherited |
Get the top-left position of the sprite image relative to the sprite image source texture.
If the sprite image was created from the whole source texture, this function returns {0, 0}
unsigned int ime::SpriteSheet::getRowCount | ( | ) | const |
Get the number of rows in the spritesheet.
|
inherited |
Get the size of the sprite image in pixels.
The x component is width whilst the y component is the height of the sprite image
Vector2u ime::SpriteSheet::getSizeInFrames | ( | ) | const |
Get the size of the spritesheet in frames.
Vector2u ime::SpriteSheet::getSpaceBetweenFrames | ( | ) | const |
Get the space between frames in the spritesheet.
Sprite ime::SpriteSheet::getSprite | ( | const std::string & | alias | ) | const |
Get a sprite from the index with a given alias.
alias | The name given to a frame in the spritesheet |
Get a sprite from an index.
index | Index to get the sprite from |
Note than index starts at {0, 0}
Get all the sprites in a range.
start | The start of the range (inclusive) |
end | The end of the range (inclusive) |
The range must either be on a row or column. For rows the x components of the start and end arguments must be the same. Similarly, for columns, the y components of the start and end must be the same otherwise an empty vector will be returned. In addition for components that varies (row or column), the start component must be less than the end component. An empty vector will also be returned if the either the start or end index is out of bounds
Note that start and end start at {0, 0}
std::vector<Sprite> ime::SpriteSheet::getSpritesOnColumn | ( | unsigned int | column | ) | const |
Get all the sprites in a column.
column | The column to get the sprites from |
Note that column starts at 0
std::vector<Sprite> ime::SpriteSheet::getSpritesOnRow | ( | unsigned int | row | ) | const |
Get all the sprites in a row.
row | The row to get the sprites from |
Note that row starts at 0
|
inherited |
|
inherited |
Get the source texture of the sprite image.
|
inherited |
Get the width of the sprite image in pixels.
bool ime::SpriteSheet::hasFrame | ( | const std::string & | alias | ) | const |
Check if there is a frame with a specified alias.
alias | Name of the alias given to a frame |
bool ime::SpriteSheet::hasFrame | ( | Index | index | ) | const |
Check if an index has a frame or not.
index | Index to be checked |
Note that index starts at {0, 0}
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
Note that an object may have more than one destruction listeners, however, you have to keep the returned id if you may want to remove the callback at a later time
|
inherited |
Add an event listener to an event.
event | The name of the event to add an an event listener to |
callback | The function to be executed when the event takes place |
Unlike onPropertyChange, this function registers event listeners to events that occur when something happens to the object, or when the object does something (action events). Usually the name of the event/action is the name of the function:
Add an event listener to a property change event.
callback | The function to be executed when the property changes |
Note that only one callback function may be registered with this function. This means that adding a new event listener overwrites the previous event listener. To remove the callback, pass a nullptr as an argument. The function may be useful if you want to write the logic for property changes in one function.
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to listen for |
callback | The function to be executed when the property changes |
A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, for the setTag function, the property that the function modifies is Tag.
Note that when adding a property change event listener, the name of the property must be in lowercase:
Unlike onPropertyChange(const Callback&) you can add multiple event listeners to the same property using this function. However you must store the unique id of the event listener if you wish to remove it at a later time
|
inherited |
Check if two objects are not the same object.
rhs | Object to compare against this object |
Two objects are different from each other if they have different object id's
|
default |
Copy assignment operator.
|
defaultnoexcept |
Move assignment operator.
|
inherited |
Check if two objects are the same object or not.
rhs | Object to compare against this object |
Two objects are the same object if they have the same object id. Recall that each object instance has a unique id
|
inherited |
Remove a destruction listener form the object.
The | id of the destruction listener to be removed |
|
inherited |
Assign the object an alias.
name | The alias of the object |
This function is useful if you want to refer to the object by tag instead of its id. Unlike an object id, multiple objects may have the same tag.
By default, the tag is an empty string
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove event listener from |
id | The unique id of the event listener to be removed |