Dauphine  0.1
A platforming/stealth game in a medieval fantasy setting, developed with SDL2.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Sprite Class Reference

Visual representation of game objects. More...

#include <Sprite.h>

Public Types

typedef std::shared_ptr< SpriteSpritePtr
 Typedef of a Sprite shared pointer. More...
 

Public Member Functions

 Sprite (const std::string &path_)
 The constructor. More...
 
 Sprite (SDL_Surface *const surface_)
 
 ~Sprite ()
 The destructor. More...
 
void render (const double x_, const double y_, SDL_Rect *const clip_=nullptr, const bool stretch_=false, const double angle_=0.0, SDL_Point *const center_=nullptr, SDL_RendererFlip flip_=SDL_FLIP_NONE)
 Renders the sprite. More...
 
unsigned int getWidth ()
 
void setWidth (unsigned int width_)
 
void setHeight (unsigned int height_)
 
unsigned int getHeight ()
 
void setHorizontalFlip (bool isRigth_)
 
std::string getPath ()
 

Private Member Functions

void loadFrom (const std::string &path_)
 Loads image from a path. More...
 
SDL_Texture * surfaceToTexture (SDL_Surface *const surface_)
 

Private Attributes

SDL_Texture * sdlTexture
 The SDL texture to use as the image. More...
 
unsigned int width
 The loaded image's width. More...
 
unsigned int height
 The loaded image's width. More...
 
const std::string path
 Holds the path from where the Sprite was loaded. More...
 
bool flipHorizontal
 When true flip the image.
 

Detailed Description

Visual representation of game objects.

Holds the SDL_Texture from the SDL2 library.

Member Typedef Documentation

typedef std::shared_ptr<Sprite> Sprite::SpritePtr

Typedef of a Sprite shared pointer.

Constructor & Destructor Documentation

Sprite::Sprite ( const std::string &  path_)

The constructor.

Initializes all the data, and sets the desired renderer. Loads image with the desired path.

Parameters
path_: the image path.
See Also
Sprite::loadFrom
Sprite::~Sprite ( )

The destructor.

Destroys the SDL_Texture.

Member Function Documentation

unsigned int Sprite::getHeight ( )
Returns
The Sprite height.
unsigned int Sprite::getWidth ( )
Returns
The Sprite width.
void Sprite::loadFrom ( const std::string &  path_)
private

Loads image from a path.

Given an existing path for an image, loads the SDL_Texture from it.

Parameters
path_: the image path.
Note
Error message is logged if the sprite's SDL_Texture (sdlTexture) is null after method.
void Sprite::render ( const double  x_,
const double  y_,
SDL_Rect *const  clip_ = nullptr,
const bool  stretch_ = false,
const double  angle_ = 0.0,
SDL_Point *const  center_ = nullptr,
SDL_RendererFlip  flip_ = SDL_FLIP_NONE 
)

Renders the sprite.

Copy the SDL_Texture onto the renderer, at the desired x,y position.

Parameters
x_: The position on the x axis of the screen.
y_: The position on the y axis of the screen.
clip_: Clips the texture, on the SDL_Rect bounds. If omitted, renders entire texture.
stretch_: Whether to stretch the image to the entire screen or not.
angle_: An angle in degrees that indicates the rotation that will be applied to the renderQuad. If omitted, no rotation will be applied.
center_: A point indicating the point around which renderQuad will be rotated. If omitted, rotation will be done in width/height center.
flip_: Value static which flipping actions should be performed on the texture.
Note
The only obligatory parameters are x_ and y_.
If the Window renderer is null, will halt the game.
If it fails to render, logs an error message.

Member Data Documentation

unsigned int Sprite::height
private

The loaded image's width.

const std::string Sprite::path
private

Holds the path from where the Sprite was loaded.

SDL_Texture* Sprite::sdlTexture
private

The SDL texture to use as the image.

unsigned int Sprite::width
private

The loaded image's width.


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