Slippers Engine
 
Loading...
Searching...
No Matches
SpriteString Class Reference

Responsible for writing text to the screen. More...

#include <SpriteString.h>

Collaboration diagram for SpriteString:
Collaboration graph

Public Member Functions

 SpriteString (SpriteFont *sf)
 Creates an empty text with a given font.
 
 SpriteString (SpriteFont *sf, std::string s, float x, float y, float kern=5)
 Creates a text at a given location with default kerning of 5.
 
float GetHeight ()
 Returns width of entire text minus kerning.
 
float GetWidth ()
 Returns height of tallest letter in string.
 
float GetKerning ()
 Returns kerning.
 
void SetKerning (float k)
 Sets Kerning.
 
void Set (float x, float y)
 Sets the top left starting point.
 
void Set (std::string s)
 Sets the string to be printed.
 
void Set (std::string s, float x, float y)
 Sets the string to be printed and the top left starting point.
 
void Set (std::string s, float x, float y, float kern)
 Sets the string to be printed, the top left starting point, and the kerning.
 
void Set (SpriteFont *sf, std::string s, float x, float y)
 Sets the font, the string to be printed, and the top left starting point.
 
void Set (SpriteFont *sf, std::string s, float x, float y, float kern)
 Sets the font, the string to be printed, the top left starting point, and the kerning.
 
void Render ()
 Renders the text to the screen.
 

Detailed Description

Responsible for writing text to the screen.

Example:
StringDemo.h

#include "GameObject.h"
class Sprite;
class SpriteFont;
class Panel;
class StringDemo : public GameObject {
public:
StringDemo();
StringDemo(const StringDemo&) = default;
StringDemo& operator=(const StringDemo&) = default;
~StringDemo();
virtual void Update();
virtual void Draw2D();
private:
SpriteString* demoStringOne;
SpriteString* demoStringTwo;
int counter;
};
virtual void Draw2D()
Fill this with code that occurs during the Draw2D phase.
Definition Drawable2D.h:51
Responsible for GameObject centralization.
Definition GameObject.h:179
Extra feature of ScreenLog.
Definition Panel.h:15
Responsible for Sprite Creation and Positioning.
Definition Sprite.h:129
SpriteString(SpriteFont *sf)
Creates an empty text with a given font.
Definition SpriteString.cpp:5
virtual void Update()
Fill this with code that occurs during the Update phase.
Definition Updatable.h:54

StringDemo.cpp

#include "StringDemo.h"
#include "SpriteString.h"
#include "FontManager.h"
StringDemo::StringDemo(){
counter = 0;
//This creates an empty string with the given font
demoStringOne = new SpriteString(FontManager::GetFont("Demo Font One");
//Manually sets kerning to 4
demoStringOne->SetKerning(4.0f);
//Sets the location to the middle of the screen
demoStringOne->Set(static_cast<float>(Game::GetWidth() / 2.0f), static_cast<float>(Game::GetHeight() / 2.0f));
//This puts the string in the top left corner with 2 pixel kerning
demoStringTwo = new SpriteString(FontManager::GetFont("Demo Font Two"), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, static_cast<float>(Game::GetHeight()), 2.0f);
}
StringDemo::~StringDemo(){
delete demoStringOne;
delete demoStringTwo;
}
void StringDemo::Update(){
//Sets the text on demoStringOne to count up every frame
demoStringOne->Set("Counter: " + std::to_string(counter));
counter++;
}
void StringDemo::Draw2D(){
demoStringOne->Render();
demoStringTwo->Render();
}
void SubmitRegistration()
Called when wanting to show sprites on screen.
Definition Drawable2D.cpp:37
static SpriteFont * GetFont(const MapKey &key)
Returns Font pointer with given KEY.
Definition FontManager.h:68
static int GetHeight()
Returns window's height in pixels.
Definition Game.h:161
static int GetWidth()
Returns window's width in pixels.
Definition Game.h:167
void SubmitRegistration()
Called when wanting to make changes every frame.
Definition Updatable.cpp:37

Constructor & Destructor Documentation

◆ SpriteString() [1/2]

SpriteString::SpriteString ( SpriteFont * sf)

Creates an empty text with a given font.

Parameters
sf

◆ SpriteString() [2/2]

SpriteString::SpriteString ( SpriteFont * sf,
std::string s,
float x,
float y,
float kern = 5 )

Creates a text at a given location with default kerning of 5.

Parameters
sf
s
x
y
kern

Member Function Documentation

◆ GetHeight()

float SpriteString::GetHeight ( )

Returns width of entire text minus kerning.

Returns
float

◆ GetKerning()

float SpriteString::GetKerning ( )

Returns kerning.

Returns
float

◆ GetWidth()

float SpriteString::GetWidth ( )

Returns height of tallest letter in string.

Returns
float

◆ Render()

void SpriteString::Render ( )

Renders the text to the screen.

demoString->Render();

◆ Set() [1/6]

void SpriteString::Set ( float x,
float y )

Sets the top left starting point.

Parameters
x
y

◆ Set() [2/6]

void SpriteString::Set ( SpriteFont * sf,
std::string s,
float x,
float y )

Sets the font, the string to be printed, and the top left starting point.

Parameters
sf
s
x
y

◆ Set() [3/6]

void SpriteString::Set ( SpriteFont * sf,
std::string s,
float x,
float y,
float kern )

Sets the font, the string to be printed, the top left starting point, and the kerning.

Parameters
sf
s
x
y
kern

◆ Set() [4/6]

void SpriteString::Set ( std::string s)

Sets the string to be printed.

Parameters
s

◆ Set() [5/6]

void SpriteString::Set ( std::string s,
float x,
float y )

Sets the string to be printed and the top left starting point.

Parameters
s
x
y

◆ Set() [6/6]

void SpriteString::Set ( std::string s,
float x,
float y,
float kern )

Sets the string to be printed, the top left starting point, and the kerning.

Parameters
s
x
y
kern

◆ SetKerning()

void SpriteString::SetKerning ( float k)

Sets Kerning.

Parameters
k