ASGE
3.2.0
Simple Game Framework in GL
|
#include <Sprite.hpp>
Public Types | |
enum | FlipFlags { NORMAL = 0x00 , FLIP_X = 0x01 , FLIP_Y = 0x02 , FLIP_XY = 0x04 , FLIP_BOTH = FLIP_X | FLIP_Y } |
enum | SourceRectIndex { SRC_START_X = 0 , SRC_START_Y = 1 , SRC_LENGTH_X = 2 , SRC_LENGTH_Y = 3 } |
enum class | AttachMode : int8_t { DEFAULT = 0x00 , KEEP_DIMS = 0x01 , KEEP_UVS = 0x02 , KEEP_TINT = 0x04 , KEEP_ROTATION = 0x08 , GENERATE_MIPS = 0x10 } |
Public Member Functions | |
virtual | ~Sprite ()=default |
virtual bool | loadTexture (const std::string &, AttachMode mode)=0 |
bool | loadTexture (const std::string &) |
virtual Texture2D * | getTexture () const =0 |
float | xPos () const noexcept |
void | xPos (float x) noexcept |
float | yPos () const noexcept |
void | yPos (float y) noexcept |
float | width () const noexcept |
void | width (float width) noexcept |
float | height () const noexcept |
void | height (float height) noexcept |
void | dimensions (float &width, float &height) const noexcept |
std::tuple< int, int > | dimensions () const noexcept |
float | rotationInRadians () const noexcept |
void | rotationInRadians (float rotation_radians) |
float | scale () const noexcept |
void | scale (float scale_value) noexcept |
Colour | colour () const noexcept |
void | colour (ASGE::Colour sprite_colour) noexcept |
bool | isFlippedOnX () const noexcept |
bool | isFlippedOnY () const noexcept |
bool | isFlippedOnXY () const noexcept |
void | setFlipFlags (FlipFlags flags) noexcept |
FlipFlags | flipFlags () const noexcept |
void | opacity (float alpha) noexcept |
float | opacity () const noexcept |
float * | srcRect () noexcept |
const float * | srcRect () const noexcept |
SpriteBounds | getLocalBounds () const noexcept |
SpriteBounds | getWorldBounds () const noexcept |
virtual bool | attach (ASGE::Texture2D *texture2D, AttachMode mode) noexcept=0 |
virtual bool | attach (ASGE::Texture2D *texture2D) noexcept |
ASGE::Point2D | midpoint () const |
int16_t | getGlobalZOrder () const noexcept |
void | setGlobalZOrder (int16_t new_z_order) noexcept |
const SHADER_LIB::Shader * | getPixelShader () const noexcept |
SHADER_LIB::Shader * | getPixelShader () noexcept |
void | setPixelShader (SHADER_LIB::Shader *shader) noexcept |
bool | hasPixelShader () const noexcept |
void | setMagFilter (Texture2D::MagFilter requested_filter) const noexcept |
Protected Member Functions | |
std::array< float, 2 > & | dimensions () |
Friends | |
AttachMode | operator| (AttachMode lhs, AttachMode rhs) |
AttachMode | operator& (AttachMode lhs, AttachMode rhs) |
An ASGE supported sprite.
Used to render and load textures. Includes the ability to resize, scale, flip, recolour etc. 2D games are made up of these. This is the interface that defines the platform specific implementation's API. The management and loading of GPU data is handled within the inherited specialisations.
Definition at line 45 of file Sprite.hpp.
|
strong |
Flags to control attachments of textures. When attaching a texture to the sprite, by default the sprite's settings will be reset to match the newly attached texture. These flags allow the user to prevent certain resets from occurs.
Definition at line 85 of file Sprite.hpp.
Flags to control the flipping of the sprite.
Used to flip the texture's UV coordinates. The flip is performed on the CPU when calculating the UVs.
Definition at line 54 of file Sprite.hpp.
a simple enum to help with src rectangles These enums provide the index numbers that are used for manipulating the UV coordinates when mapping textures to sprites. They form a rectangle that contents delimit the range to use when calculating the source UV coordinates.
Definition at line 71 of file Sprite.hpp.
|
virtualdefault |
Default destructor.
The destructor does not free the memory used on the GPU. This is handled inside the platform's specific implementation.
|
pure virtualnoexcept |
Attaches a texture to the sprite.
Sprites are simply textures which have transform and rendering properties applied to them. They are mostly for convenience of rendering. It is possible to swap out the texture attached to the sprite. Doing so will result the UV coordinates and width and height of the sprite to match the texture, so any changes will need to be reapplied.
texture2D | The texture to attach. |
|
noexcept |
Gets the colour of the sprite.
The colour of the sprite can be influenced by providing a tint. The pixel shader will then apply the tint on the resultant pixel when sampling the texture.
|
noexcept |
Sets the colour of the sprite.
The colour of the sprite can be influenced by providing a tint. The pixel shader will then apply the tint on the resultant pixel when sampling the texture.
[in] | sprite_colour | The sprite's colour. |
|
protected |
Retrieves the dimensions.
|
noexcept |
Gets the non-transformed height and the width of the sprite.
|
noexcept |
Gets the non-transformed height and the width of the sprite.
Updates the width and the height of two parameters passed in to the function. It does not return a value. The width and height is found in the resultant parameters.
[in] | width | The sprites width. |
[in] | height | The sprites height. |
|
noexcept |
Returns the current flip flags for the sprite.
Flip flags can be used to change the orientation of the texture's render. It does this by altering UV mappings. Use this function to retrieve the current flip flags used for rendering the attached texture.
|
noexcept |
Retrieves the rendering order (layer) of the sprite.
|
noexcept |
Retrieves the sprite's 4 points in local space.
Simply returns the sprite's original and unmodified dimensions. No transforms will be applied, meaning rotation and scaling are absent and the points can be considered as local or model space. These points can be used as the starting basis of an AABB or for additional collision detection.
|
noexcept |
Retrieves any attached shader.
|
noexcept |
Retrieves any attached shader.
|
pure virtual |
Pure virtual function for retrieving the loaded texture.
This is handled inside the platform's specific implementation.
|
noexcept |
Retrieves the sprite's 4 points in world space.
Returns the 4 vertices that delimit the sprite's position in world space. Any transforms (scaling and rotation) have already been applied. This is useful for when you need to know the projected location i.e. calculating a bounding volume.
|
noexcept |
Checks to see if this sprite has a pixel shader attached.
|
noexcept |
Gets the height of the sprite.
Height is used (along with scale, rotation etc) to determine how tall a sprite will be when it's rendered to the screen. This is the non-transformed height of the sprite.
|
noexcept |
Sets the height of the sprite.
Height is used (along with scale, rotation etc) to determine how tall a sprite will be when it's rendered to the screen. This is the non-transformed height of the sprite.
[in] | height | The sprites height. |
|
noexcept |
Checks to see if the texture is flipped on the X axis.
It is possible to flip the UV coordinates used on the sprite's texture. This will check to see if the X axis is flipped.
|
noexcept |
Checks to see if the texture is flipped diagonally.
|
noexcept |
Checks to see if the texture is flipped on the Y axis.
It is possible to flip the UV coordinates used on the sprite's texture. This will check to see if the Y axis is flipped.
bool ASGE::Sprite::loadTexture | ( | const std::string & | ) |
|
pure virtual |
Pure virtual function for loading texture on to the GPU.
This is handled inside the platform's specific implementation.
ASGE::Point2D ASGE::Sprite::midpoint | ( | ) | const |
Calculates the mid-point of the sprite.
Sprites origins are normally 0,0, which maps to the top left. This function returns the mid-point of the sprite based on its with and height and its current position in the world.
|
noexcept |
Retrieves the opacity of the sprite.
This function let's you obtain the opacity of the sprite. The opacity is controlled by using the alpha channel. 1.0f is opaque and 0.0f is completely transparent.
|
noexcept |
Sets the opacity of the sprite.
This function let's you control the opacity of the sprite by modifying the alpha channel during the render cycle. 1.0f is opaque and 0.0f is completely transparent.
[in] | alpha | The new value for the alpha channel. |
|
noexcept |
Gets the rotation of the sprite in radians.
The angle of rotation is used to rotate the sprite around it's origin. The origin defaults to the mid-point of the sprite. The angle of rotation is expressed in radians.
void ASGE::Sprite::rotationInRadians | ( | float | rotation_radians | ) |
Sets the rotation of the sprite in radians.
The angle of rotation is used to rotate the sprite around it's origin. The origin defaults to the mid-point of the sprite. The angle of rotation is expressed in radians.
[in] | rotation_radians | The angle of rotation in radians. |
|
noexcept |
Gets the scale of the sprite.
The scale can be adjusted to automatically make the sprite bigger or smaller than it's original size, allowing for on the fly alterations without having to edit the sprite's true size. The scaling operation is performed in both axis.
|
noexcept |
Sets the scale of the sprite.
The scale can be adjusted to automatically make the sprite bigger or smaller than it's original size, allowing for on the fly alterations without having to edit the sprite's true size. The scaling operation is performed in both axis.
[in] | scale_value | The scaling factor to apply to the sprite. |
|
noexcept |
Sets the flip state of the texture.
It is possible to flip the UV coordinates used on the sprite's texture. This function allows setting of the flip flags. These are then used to control shader's UV mappings.
flags | The flip flags to apply to the texture. |
|
noexcept |
Sets the rendering order (layer) of the sprite.
When rendering it is often necessary to control the order in which sprites, text or even UI elements are rendered. For example, if parts of the UI were rendered before the background they would end up hidden. Z-ordering is a common approach to controlling this behaviour and is essential when using batch rendering.
[in] | new_z_order | The z-order to apply to sprite. |
Example
In this image you can see an example of when the z-order for a sprite is not set correctly. The blocks below the player should have a lower z-order than the player's sprite to ensure they are rendered first.
|
noexcept |
Sets the magnification filter on the attached texture.
Use this function to alter the texture sampling behaviour when the attached texture is being read.
requested_filter |
|
noexcept |
Attaches a shader to the sprite.
When rendering in ASGE, it is possible to create custom pixel shaders that can have additional uniforms which can be updated by the developer. You can either flag the renderer to switch shaders, or if you only need a small subset of sprites to use the custom shader, attach them directly. The renderer will take care of switching shaders out when rendering to the GPU.
[in] | shader | The shader to attach. |
|
noexcept |
Gets a read-only source rectangle used for rendering.
It is possible to render a subset of a sprite using a rectangle. The rectangle will use [0] and [1] for the beginning x and y position in the texture and [2] and [3] for the width and height. This is useful when the texture is a sprite sheet.
|
noexcept |
Gets the source rectangle used for rendering.
It is possible to render a subset of a sprite using a rectangle. The rectangle will use [0] and [1] for the beginning x and y position in the texture and [2] and [3] for the width and height. This is useful when the texture is a sprite sheet.
|
noexcept |
Gets the width of the sprite.
Width is used (along with scale, rotation etc) to determine how wide/long a sprite will be when it's rendered to the screen. This is the non-transformed width of the sprite.
|
noexcept |
Sets the width of the sprite.
Width is used (along with scale, rotation etc) to determine how wide/long a sprite will be when it's rendered to the screen. This is the non-transformed width of the sprite.
[in] | width | The sprites width. |
|
noexcept |
Returns the sprite's position on the X axis.
Sprite positions are described using Cartesian Coordinates. The horizontal position in this engine is labelled X and runs from left to right. If an ASGE::Camera is not used it is mapped directly to the screen via the viewport.
|
noexcept |
Updates the sprite's position on the X axis.
Sprite positions are described using Cartesian Coordinates. The horizontal position in this engine is labelled X and runs from left to right. If an ASGE::Camera is not used it is mapped directly to the screen via the viewport.
[in] | x | The sprites new position on the x axis. |
|
noexcept |
Returns the sprite's position on the Y axis.
Sprite positions are described using Cartesian Coordinates. The vertical position in this engine is labelled y and runs from top to bottom. If an ASGE::Camera is not used it is mapped directly to the screen via the viewport.
|
noexcept |
Returns the sprite's position on the Y axis.
Sprite positions are described using Cartesian Coordinates. The vertical position in this engine is labelled y and runs from top to bottom.If an ASGE::Camera is not used it is mapped directly to the screen via the viewport.
[in] | y | The new position on the y axis |