Fireworks Engine  v2.0
Lightweight Sandbox Game Engine using OpenGL for additional Customisation and Quick Prototyping
fireworks::graphics::Sprite Class Reference

The class responsible for drawing the Sprites in the scene. More...

#include <sprite.h>

Inheritance diagram for fireworks::graphics::Sprite:
Collaboration diagram for fireworks::graphics::Sprite:

Public Member Functions

 Sprite ()
 Create and empty sprite with this constructor. More...
 
 Sprite (glm::vec3 position, glm::vec2 size, glm::vec4 color, Primitive2D primitive2d=Primitive2D::Quad)
 Create Sprite renderable. More...
 
 Sprite (glm::vec3 position, glm::vec2 size, Texture *texture, Primitive2D primitive2d=Primitive2D::Quad)
 Create Sprite renderable. More...
 
 Sprite (glm::vec3 position, glm::vec2 size, Texture *texture, glm::vec2 sheetDimension, Primitive2D primitive2d=Primitive2D::Quad)
 Create Sprite renderable. More...
 
 Sprite (glm::vec3 position, glm::vec2 size, glm::vec4 color, Shader *shader, Primitive2D primitive2d=Primitive2D::Quad)
 Create Sprite renderable. More...
 
 Sprite (glm::vec3 position, glm::vec2 size, Shader *shader, Texture *texture, Primitive2D primitive2d=Primitive2D::Quad)
 Create Sprite renderable. More...
 
 Sprite (glm::vec3 position, glm::vec2 size, Shader *shader, Texture *texture, glm::vec2 sheetDimension, Primitive2D primitive2d=Primitive2D::Quad)
 Create Sprite renderable. More...
 
void addedRigidBody2D () override
 The overridden callback function that confirms the addition of physics::RigidBody2D component to the Sprite. More...
 
void animateSprite (uint32_t frameRate, SpriteAnimationType animType)
 Animate the sprite by setting the framerate and the type of animation style. More...
 
const float getTotalFrames () const
 Gets the total frames in the sprite sheet. More...
 
- Public Member Functions inherited from fireworks::graphics::Renderable2D
 Renderable2D (glm::vec3 position, glm::vec2 size, glm::vec4 color, Primitive2D primitive2d)
 Creates the renderable. More...
 
 Renderable2D (glm::vec3 position, glm::vec2 size, glm::vec4 color, Primitive2D primitive2d, Shader *shader)
 Creates the renderable. More...
 
virtual ~Renderable2D ()
 
template<typename T >
void AddComponent (components::Component *component)
 Template methods of various ways of adding components to the renderable. More...
 
template<>
void AddComponent (components::Component *component)
 The Rigidbody2D overload template. More...
 
const glm::vec3 & getPosition () const
 Gets the position of the Renderable. More...
 
const float & getRotation () const
 Gets the rotation of the Renderable. More...
 
const glm::vec2 & getSize () const
 Gets the size of the renderable. More...
 
const glm::vec4 & getColor () const
 Gets the color of the renderable. More...
 
const Primitive2D getPrimitive () const
 Gets the primitive shape that is used to draw the renderable. More...
 
const std::vector< glm::vec2 > & getUV () const
 Gets the UV coordinates of the 2D Renderable. More...
 
const TexturegetTexture () const
 Gets the texture that is used to draw the renderable. More...
 
const GLuint getTID () const
 Gets the ID of the renderables texture. More...
 
void flipX ()
 Flip the Renderable along the X-axis. More...
 
void unflipX ()
 Unflip the Renderable along the X-axis. More...
 
void flipY ()
 Flip the Renderable along the Y-axis. More...
 
void unflipY ()
 Unflip the Renderable along the X-axis. More...
 

Public Attributes

std::uint32_t frame
 The frame number in the sprite sheet. More...
 
std::uint32_t frameRate
 The rate at which the frames are displayed. More...
 
glm::vec3 & position
 The position of the Sprite. More...
 
glm::vec4 & color
 The color of the Sprite. More...
 
glm::vec2 & size
 The size of the Sprite. More...
 
float & rotation
 The rotation of the Sprite. More...
 
- Public Attributes inherited from fireworks::graphics::Renderable2D
std::uint32_t objectID
 The unique ID of the renderable object. More...
 
Shadershader
 The Shader used to draw the particular renderable. More...
 
bool flippedX
 tells whether or not the renderable is flipped on the X-axis or not More...
 
bool flippedY
 tells whether or not the renderable is flipped on the Y-axis or not More...
 
std::vector< components::Component * > components
 The collection of Components that is attached to the renderable. More...
 

Additional Inherited Members

- Protected Member Functions inherited from fireworks::graphics::Renderable2D
 Renderable2D ()
 Create an empty renderable. More...
 
- Protected Attributes inherited from fireworks::graphics::Renderable2D
glm::vec2 m_Size
 The size of the renderable. More...
 
glm::vec3 m_Position
 The position of the renderable. More...
 
glm::vec4 m_Color
 The color of the renderable. More...
 
float m_Rotation
 The rotation of the renderable along the Z-Axis. More...
 
Primitive2D m_Primitive2D
 The primitive that is used to draw the renderable. More...
 
std::vector< glm::vec2 > m_UV
 The UV coordinates of the renderable. More...
 
Texturem_Texture
 The texture (if any) used by the renderable. More...
 

Detailed Description

The class responsible for drawing the Sprites in the scene.

Constructor & Destructor Documentation

◆ Sprite() [1/7]

fireworks::graphics::Sprite::Sprite ( )

Create and empty sprite with this constructor.

◆ Sprite() [2/7]

fireworks::graphics::Sprite::Sprite ( glm::vec3  position,
glm::vec2  size,
glm::vec4  color,
Primitive2D  primitive2d = Primitive2D::Quad 
)

Create Sprite renderable.

Parameters
positionThe position at which the sprite should be rendered at
sizeThe dimensions of the sprite color The color of the sprite
primitive2dThe primitive shape with which the Sprite should be rendered with
Warning
This overload is to be used with the graphics::BatchRenderer2D because it doesn't not accept any shader

◆ Sprite() [3/7]

fireworks::graphics::Sprite::Sprite ( glm::vec3  position,
glm::vec2  size,
Texture texture,
Primitive2D  primitive2d = Primitive2D::Quad 
)

Create Sprite renderable.

Parameters
positionThe position at which the sprite should be rendered at
sizeThe dimensions of the sprite texture The Texture with which the sprite should be rendered with
primitive2dThe primitive shape with which the Sprite should be rendered with
Warning
This overload is to be used with the graphics::BatchRenderer2D because it doesn't not accept any shader
See also
Texture for more information on how to Textures

◆ Sprite() [4/7]

fireworks::graphics::Sprite::Sprite ( glm::vec3  position,
glm::vec2  size,
Texture texture,
glm::vec2  sheetDimension,
Primitive2D  primitive2d = Primitive2D::Quad 
)

Create Sprite renderable.

Parameters
positionThe position at which the sprite should be rendered at
sizeThe dimensions of the sprite texture The Texture with which the sprite should be rendered with
sheetDimensionThe dimensions of the sprite sheet i.e. no of sprites in the sheet not the actual dimensions of the sheet
primitive2dThe primitive shape with which the Sprite should be rendered with
Attention
sheetDimension requires the the number of sprites in the (row, column) count glm::vec2 and not that actual dimensions of the sheet itself
Warning
This overload is to be used with the graphics::BatchRenderer2D because it doesn't not accept any shader
See also
Texture for more information on how to Textures

◆ Sprite() [5/7]

fireworks::graphics::Sprite::Sprite ( glm::vec3  position,
glm::vec2  size,
glm::vec4  color,
Shader shader,
Primitive2D  primitive2d = Primitive2D::Quad 
)

Create Sprite renderable.

Parameters
positionThe position at which the sprite should be rendered at
sizeThe dimensions of the sprite color The color of the sprite
shaderThe shader with which you want the sprite to be rendered with
primitive2dThe primitive shape with which the Sprite should be rendered with
Warning
This overload is to be used with the graphics::InstanceRenderer2D if you want the shader to be used

◆ Sprite() [6/7]

fireworks::graphics::Sprite::Sprite ( glm::vec3  position,
glm::vec2  size,
Shader shader,
Texture texture,
Primitive2D  primitive2d = Primitive2D::Quad 
)

Create Sprite renderable.

Parameters
positionThe position at which the sprite should be rendered at
sizeThe dimensions of the sprite color The color of the sprite
shaderThe shader with which you want the sprite to be rendered with texture The Texture with which the sprite should be rendered with
primitive2dThe primitive shape with which the Sprite should be rendered with
Warning
This overload is to be used with the graphics::InstanceRenderer2D if you want the shader to be used

◆ Sprite() [7/7]

fireworks::graphics::Sprite::Sprite ( glm::vec3  position,
glm::vec2  size,
Shader shader,
Texture texture,
glm::vec2  sheetDimension,
Primitive2D  primitive2d = Primitive2D::Quad 
)

Create Sprite renderable.

Parameters
positionThe position at which the sprite should be rendered at
sizeThe dimensions of the sprite color The color of the sprite
shaderThe shader with which you want the sprite to be rendered with texture The Texture with which the sprite should be rendered with
sheetDimensionThe dimensions of the sprite sheet i.e. no of sprites in the sheet not the actual dimensions of the sheet
primitive2dThe primitive shape with which the Sprite should be rendered with
Attention
sheetDimension requires the the number of sprites in the (row, column) count glm::vec2 and not that actual dimensions of the sheet itself
Warning
This overload is to be used with the graphics::InstanceRenderer2D if you want the shader to be used

Member Function Documentation

◆ addedRigidBody2D()

void fireworks::graphics::Sprite::addedRigidBody2D ( )
overridevirtual

The overridden callback function that confirms the addition of physics::RigidBody2D component to the Sprite.

Reimplemented from fireworks::graphics::Renderable2D.

◆ animateSprite()

void fireworks::graphics::Sprite::animateSprite ( uint32_t  frameRate,
SpriteAnimationType  animType 
)

Animate the sprite by setting the framerate and the type of animation style.

Parameters
frameRateThe frame rate at which you want the animation to play
animTypeThe type of animation
See also
See graphics::SpriteAnimationType for more information

◆ getTotalFrames()

const float fireworks::graphics::Sprite::getTotalFrames ( ) const
inline

Gets the total frames in the sprite sheet.

Member Data Documentation

◆ color

glm::vec4& fireworks::graphics::Sprite::color

The color of the Sprite.

◆ frame

std::uint32_t fireworks::graphics::Sprite::frame
mutable

The frame number in the sprite sheet.

Note
We use Row major way conversion of 2D sheet into 1D

◆ frameRate

std::uint32_t fireworks::graphics::Sprite::frameRate

The rate at which the frames are displayed.

Note
low frameRate means frames change faster

◆ position

glm::vec3& fireworks::graphics::Sprite::position

The position of the Sprite.

◆ rotation

float& fireworks::graphics::Sprite::rotation

The rotation of the Sprite.

◆ size

glm::vec2& fireworks::graphics::Sprite::size

The size of the Sprite.


The documentation for this class was generated from the following files: