Abstract base class for image containers. More...
#include <SpriteImage.h>
Public Types | |
using | Ptr = std::shared_ptr< SpriteImage > |
A shared sprite pointer. More... | |
Public Member Functions | |
SpriteImage (const std::string &sourceTexture, UIntRect area={}) | |
Constructor. More... | |
SpriteImage (const SpriteImage &)=default | |
Copy constructor. More... | |
SpriteImage & | operator= (const SpriteImage &)=default |
Copy assignment operator. More... | |
SpriteImage (SpriteImage &&) noexcept=default | |
Move constructor. More... | |
SpriteImage & | operator= (SpriteImage &&) noexcept=default |
Move assignment operator. 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... | |
~SpriteImage () override=0 | |
Destructor. 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... | |
virtual std::string | getClassName () const =0 |
Get the name of the concrete class. 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... | |
Abstract base class for image containers.
A sprite image is a collection of smaller images packed together into a single image. The sub-images may be of the same size or of varying dimensions. In addition, the sub-images may be arranged in grid formation or tightly packed next to each other in the sprite image. A sprite image simplifies file management and increases performance as we only have to deal with a single texture instead of multiple textures. For example, imagine a character which has a walking and running animation in all four directions (Up, right. down and left) and each animation has 15 frames. This would require 120 individual images files!. With a sprite image all that information can be stored in a single image file and accessed later using coordinates or indexes
Definition at line 51 of file SpriteImage.h.
using ime::SpriteImage::Ptr = std::shared_ptr<SpriteImage> |
A shared sprite pointer.
Definition at line 53 of file SpriteImage.h.
|
explicit |
Constructor.
sourceTexture | The filename of the sprite image on the disk |
area | Sub-rectangle to construct sprite image from |
FileNotFound | If the image could not be found on the disk |
The area can be used to construct the sprite image from a sub-rectangle of the sourceTexture. To construct the sprite image from the whole sourceTexture (default), leave the area argument unspecified. If the area rectangle crosses the bounds of the sourceTexture, it is adjusted to fit the sourceTexture size
|
default |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
overridepure virtual |
Destructor.
|
protected |
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
|
pure virtualinherited |
Get the name of the concrete class.
This function is implemented by all internal classes that inherit from this class.
Implemented in ime::Tile, ime::SpriteSheet, ime::Sprite, ime::RectangleShape, ime::ConvexShape, ime::CircleShape, ime::Camera, ime::Scene, ime::RenderLayerContainer, ime::RenderLayer, ime::TargetGridMover, ime::RandomGridMover, ime::KeyboardGridMover, ime::DistanceJoint, ime::PolygonCollider, ime::EdgeCollider, ime::CircleCollider, ime::BoxCollider, ime::Body, ime::AABB, and ime::GameObject.
|
overridevirtual |
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::SpriteImage::getHeight | ( | ) | const |
Get the height of the sprite image in pixels.
|
inherited |
Get the id of the object.
Each object has a unique id
Vector2u ime::SpriteImage::getRelativePosition | ( | ) | const |
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}
Vector2u ime::SpriteImage::getSize | ( | ) | const |
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
|
inherited |
const Texture& ime::SpriteImage::getTexture | ( | ) | const |
Get the source texture of the sprite image.
unsigned int ime::SpriteImage::getWidth | ( | ) | const |
Get the width of the sprite image in pixels.
|
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 |