raylibstarter 0.1.0
game::core::Sprite Class Reference

The Sprite class specifies position and degree of rotation on the screen for an associated VRAM texture. More...

#include <sprite.h>

Inheritance diagram for game::core::Sprite:
Collaboration diagram for game::core::Sprite:

Public Member Functions

 Sprite ()=delete
 
 Sprite (std::shared_ptr< game::core::Texture2D > texture)
 Constructor. More...
 
 Sprite (std::shared_ptr< game::core::Texture2D > texture, int pos_x, int pos_y)
 Constructor. More...
 
 Sprite (std::shared_ptr< game::core::Texture2D > texture, int pos_x, int pos_y, float rotation)
 Constructor. More...
 
 Sprite (std::shared_ptr< game::core::Texture2D > texture, int pos_x, int pos_y, Vector2 rotation_origin, float rotation, Rectangle frame)
 Constructor. More...
 
virtual ~Sprite ()
 
void texture (const std::shared_ptr< game::core::Texture2D > &texture)
 Replaces the Texture2D object. More...
 
const std::shared_ptr< game::core::Texture2D > & texture_object () const
 
const ::Texture2D & texture () const
 
Vector2 position () const
 
const Rectangle & frame () const
 
void frame (const Rectangle &frame)
 Sets the section of the associated VRAM texture to be displayed. More...
 
virtual void Update ()
 

Public Attributes

bool visible = true
 Visibility of the Sprite. More...
 
Color tint = WHITE
 The Raylib tint applied to the VRAM texture when drawing. Defulat ist Raylib WHITE. More...
 
Vector2 rotation_origin
 The sprites rotation origin, centered by default. More...
 
float rotation = 0.0f
 The sprites rotation angle. Default is 0. More...
 
int pos_x = 0
 The sprites x position. More...
 
int pos_y = 0
 The sprites y position. More...
 

Protected Attributes

std::shared_ptr< game::core::Texture2Dtexture_
 The sprites Texture2D. More...
 
Rectangle frame_
 The section of the associated VRAM texture to be displayed as Raylib Rectangle structure. More...
 

Detailed Description

The Sprite class specifies position and degree of rotation on the screen for an associated VRAM texture.

Besides the position and rotation angle, a sprite object is further defined by its rotation origin, its tint and its visibility attribute. In addition, the visible section ("frame") of the associated VRAM texture can be specified. This is especially important for the SpriteAnimated class derived from this class.

Sprites can be drawn using the game::core::Renderer::DrawTexture function. However, the preferred way is to create Actor objects. These contain a sprite and are automatically drawn if they are referenced in the actors map of a Scene object.

Definition at line 21 of file sprite.h.

Constructor & Destructor Documentation

◆ Sprite() [1/5]

game::core::Sprite::Sprite ( )
delete

◆ Sprite() [2/5]

game::core::Sprite::Sprite ( std::shared_ptr< game::core::Texture2D texture)
explicit

Constructor.

This constructor sets the section of the texture to be displayed to its full size. In addition, the rotation origin is set to its center and rotation angle = 0. The sprites default position is {0, 0}.

Parameters
textureShared pointer to a Texture2D object.

Definition at line 7 of file sprite.cpp.

◆ Sprite() [3/5]

game::core::Sprite::Sprite ( std::shared_ptr< game::core::Texture2D texture,
int  pos_x,
int  pos_y 
)

Constructor.

This constructor sets the section of the texture to be displayed to its full size. In addition, the rotation origin is set to its center and rotation angle = 0. The sprites position can be specified.

Parameters
textureShared pointer to a Texture2D object.
pos_xThe sprites x position.
pos_yThe sprites y position.

Definition at line 12 of file sprite.cpp.

◆ Sprite() [4/5]

game::core::Sprite::Sprite ( std::shared_ptr< game::core::Texture2D texture,
int  pos_x,
int  pos_y,
float  rotation 
)

Constructor.

This constructor sets the section of the texture to be displayed to its full size. In addition, the rotation origin is set to its center. The sprites position and rotation angle can be specified.

Parameters
textureShared pointer to a Texture2D object.
pos_xThe sprites x position.
pos_yThe sprites y position.
rotationThe sprites rotation angle.

Definition at line 17 of file sprite.cpp.

◆ Sprite() [5/5]

game::core::Sprite::Sprite ( std::shared_ptr< game::core::Texture2D texture,
int  pos_x,
int  pos_y,
Vector2  rotation_origin,
float  rotation,
Rectangle  frame 
)

Constructor.

Using this constructor the sprites position, rotation angle and rotation and a Raylib Rectangle, which describes the texture section to be displayed can be specified.

Parameters
textureShared pointer to a Texture2D object.
pos_xThe sprites x position.
pos_yThe sprites y position.
rotation_originThe rotation origin.
rotationThe sprites rotation angle.
frameThe section of the associated VRAM texture to be displayed.

Definition at line 31 of file sprite.cpp.

◆ ~Sprite()

game::core::Sprite::~Sprite ( )
virtual

Definition at line 41 of file sprite.cpp.

Member Function Documentation

◆ frame() [1/2]

const Rectangle & game::core::Sprite::frame ( ) const
Returns
The section of the associated VRAM texture to be displayed as Raylib Rectangle structure.

Definition at line 67 of file sprite.cpp.

◆ frame() [2/2]

void game::core::Sprite::frame ( const Rectangle &  frame)

Sets the section of the associated VRAM texture to be displayed.

Parameters
frameRaylib Rectangle, which describes the texture section to be displayed.

Definition at line 71 of file sprite.cpp.

◆ position()

Vector2 game::core::Sprite::position ( ) const
Returns
Returns the objects coordinates as Raylib Vector structure.

Definition at line 45 of file sprite.cpp.

◆ texture() [1/2]

const ::Texture2D & game::core::Sprite::texture ( ) const
Returns
Returns a reference to the Raylib Texture2D structure associated with this object.

Definition at line 63 of file sprite.cpp.

◆ texture() [2/2]

void game::core::Sprite::texture ( const std::shared_ptr< game::core::Texture2D > &  texture)

Replaces the Texture2D object.

The section of the texture to be displayed is set to its full size. In addition, the rotation origin is set to its center.

Parameters
textureShared pointer to a Texture2D object.

Definition at line 53 of file sprite.cpp.

◆ texture_object()

const std::shared_ptr< game::core::Texture2D > & game::core::Sprite::texture_object ( ) const
Returns
Returns a shared pointer to the objects Texture2D member.

Definition at line 49 of file sprite.cpp.

◆ Update()

virtual void game::core::Sprite::Update ( )
inlinevirtual

Only relevant in derived classes, like SpiteAnimated.

Reimplemented in game::core::SpriteAnimated.

Definition at line 130 of file sprite.h.

Member Data Documentation

◆ frame_

Rectangle game::core::Sprite::frame_
protected

The section of the associated VRAM texture to be displayed as Raylib Rectangle structure.

Definition at line 27 of file sprite.h.

◆ pos_x

int game::core::Sprite::pos_x = 0

The sprites x position.

Definition at line 43 of file sprite.h.

◆ pos_y

int game::core::Sprite::pos_y = 0

The sprites y position.

Definition at line 46 of file sprite.h.

◆ rotation

float game::core::Sprite::rotation = 0.0f

The sprites rotation angle. Default is 0.

Definition at line 40 of file sprite.h.

◆ rotation_origin

Vector2 game::core::Sprite::rotation_origin

The sprites rotation origin, centered by default.

Definition at line 37 of file sprite.h.

◆ texture_

std::shared_ptr<game::core::Texture2D> game::core::Sprite::texture_
protected

The sprites Texture2D.

Definition at line 24 of file sprite.h.

◆ tint

Color game::core::Sprite::tint = WHITE

The Raylib tint applied to the VRAM texture when drawing. Defulat ist Raylib WHITE.

Definition at line 34 of file sprite.h.

◆ visible

bool game::core::Sprite::visible = true

Visibility of the Sprite.

Definition at line 31 of file sprite.h.


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