Wraith  0.1.5
Basic 3D game engine in C++
SpriteString

A SpriteString entity is used for displaying a 2D text messages on the screen. It can be used anywhere within a user defined GameObject. More...

Collaboration diagram for SpriteString:

Functions

 SpriteString::SpriteString (SpriteFont *pSpriteFont, const std::string &message, int positionX, int positionY)
 Constructor. More...
 
void SpriteString::set (SpriteFont *pSpriteFont, const std::string &message, int positionX, int positionY)
 Sets sprite string data. More...
 
void SpriteString::setPosition (int positionX, int positionY)
 Sets a position. More...
 
int SpriteString::getPositionX () const
 Gets position x coordinate. More...
 
int SpriteString::getPositionY () const
 Gets position y coordinate. More...
 
int SpriteString::getWidth () const
 Gets the width. More...
 
int SpriteString::getHeight () const
 Gets the height. More...
 
void SpriteString::render ()
 Renders the sprite string message onto the string. More...
 

Detailed Description

A SpriteString entity is used for displaying a 2D text messages on the screen. It can be used anywhere within a user defined GameObject.

A SpriteString takes in a SpriteFont pointer, a message, and the X and Y position of the screen. X = 0 and Y = 0 is the lower left corner of the screen. This is either done with the SpriteString constructor or the SpriteString::set() function. The position of the SpriteString can changed anytime.

IMPORTANT: To render a SpriteString entity, it you must call SpriteString::render() within the GameObject::draw2D() callback in order to display the sprite properly.

Here is an example of how a sprite can be used. IMPORTANT: You must include SpriteString.h and SpriteFontManager.h

#include "SpriteString.h"
#include "SpriteFontManager.h"
struct PlayerData
{
std::string _name;
int _health;
};
HUD::HUD(PlayerData* pPlayerData)
{
_pPlayerData = pPlayerData
_pUserName = new SpriteString(pFont, pPlayerData->_name, 0, 500);
_pHealth = new SpriteString();
// IMPORTANT: Submit Draw 2D Registration
// Other registrations (not really needed for sprite)
GameObject::submitUpdateRegistraion();
}
void HUD::update()
{
std::string healthMessage = "Health: " + std::to_string(_pPlayerData->_health);
_pHealth->set(pFont, "healthMessage", 0, 500);
}
void HUD::draw2D()
{
// IMPORTANT: if two sprites overlap each other
// the one that gets drawn on top is the sprite
// who's Sprite::render() was called last
_pUserName->render();
_pHealth->render();
}
A sprite font used for get characters (glyps) from a particular texture.
Definition: SpriteFont.h:18
A sprite string that handles 2D text messages on screen
Definition: SpriteString.h:18
void submitDraw2DRegistration()
Submit draw 2D registration to current scene.
Definition: Drawable.cpp:60
static SpriteFont * GetSpriteFont(const MapKey &key)
Gets a sprite font using a user defined key.
Definition: SpriteFontManager.h:93

Function Documentation

◆ getHeight()

int SpriteString::getHeight ( ) const

Gets the height.

Returns
The height.

◆ getPositionX()

int SpriteString::getPositionX ( ) const

Gets position x coordinate.

Returns
The position x coordinate.

◆ getPositionY()

int SpriteString::getPositionY ( ) const

Gets position y coordinate.

Returns
The position y coordinate.

◆ getWidth()

int SpriteString::getWidth ( ) const

Gets the width.

Returns
The width.

◆ render()

void SpriteString::render ( )

Renders the sprite string message onto the string.

This must be called within GameObject::draw2D() callback.

◆ set()

void SpriteString::set ( SpriteFont pSpriteFont,
const std::string &  message,
int  positionX,
int  positionY 
)

Sets sprite string data.

Parameters
pSpriteFontsprite font pointer.
messageThe message.
positionXThe position x coordinate.
positionYThe position y coordinate.

◆ setPosition()

void SpriteString::setPosition ( int  positionX,
int  positionY 
)

Sets a position.

Parameters
positionXThe position x coordinate.
positionYThe position y coordinate.

◆ SpriteString()

SpriteString::SpriteString ( SpriteFont pSpriteFont,
const std::string &  message,
int  positionX,
int  positionY 
)

Constructor.

Parameters
pSpriteFontsprite font pointer.
messageThe message.
positionXThe position x coordinate.
positionYThe position y coordinate.