Slippers Engine
 
Loading...
Searching...
No Matches
Sprites

Examples for Sprite use. More...

Classes

class  Sprite
 Responsible for Sprite Creation and Positioning. More...
 
class  SpriteString
 Responsible for writing text to the screen. More...
 

Detailed Description

Examples for Sprite use.

Example:
SpriteDemo.h

#include "GameObject.h"
class Sprite;
class Panel;
class SpriteDemmo : public GameObject {
public:
SpriteDemmo();
SpriteDemmo(const SpriteDemmo&) = default;
SpriteDemmo& operator=(const SpriteDemmo&) = default;
~SpriteDemmo();
virtual void Update();
virtual void Draw2D();
virtual void Alarm0();
private:
Sprite* demoSpriteOne;
SpriteString* demoStringOne;
SpriteString* demoStringTwo;
int demoNum;
Panel* p;
Panel* p2;
Panel* p3;
};
virtual void Alarm0()
Definition Alarmable.h:71
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
Responsible for writing text to the screen.
Definition SpriteString.h:82
virtual void Update()
Fill this with code that occurs during the Update phase.
Definition Updatable.h:54

SpriteDemo.cpp

#include "SpriteDemmo.h"
#include "Sprite.h"
#include "SpriteString.h"
#include "FontManager.h"
#include "TimeManager.h"
#include "ScreenLog.h"
#include "Panel.h"
SpriteDemmo::SpriteTester() {
demoNum = 5;
demoSpriteOne = new Sprite("Stitch");
demoSpriteOne->SetScaleFactor(.5f, .5f);
demoSpriteOne->SetPosition(400, 400);
demoSpriteOne->SetCenter(-300, -300);
demoSpriteOne->SetAngleDeg(90.0f);
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);
//Creates Blue Panel with Red Border
//Creates Transparent Panel
p2 = ScreenLog::CreatePanel(500, (float)Game::GetHeight() - 400);
//Creates a semi Transparent Blue Panel
p3 = ScreenLog::CreatePanel(100, (float)Game::GetHeight() - 350, Vect(.3f, .5f, .7f, .5f));
}
void SpriteDemmo::Update() {
ScreenLog::Add("Demo");
p->Add("The quick brown fox jumped over the lazy dog");
p2->Add("%i", demoNum);
p3->SetPos((float)demoNum, (float)demoNum);
p3->Add("Moving Panel");
demoSpriteOne->SetAngleDeg((demoSpriteOne->GetAngleDeg() + 50.0f) * TimeManager::GetFrameTime());
//demoSpriteOne->SetAngleRad((demoSpriteOne->GetAngleRad() + 5.0f) * TimeManager::GetFrameTime());
testString->Set("Counting" + std::to_string(demoNum));
demoNum++;
}
void SpriteDemmo::Alarm0() {
}
SpriteDemmo::~SpriteTester() {
delete demoSpriteOne;
delete demoStringOne;
delete demoStringTwo;
}
void SpriteDemmo::Draw2D() {
demoSpriteOne->Render();
demoStringOne->Render();
demoStringTwo->Render();
}
void SubmitRegistration(float t, AlarmableManager::ALARM_ID id)
Called when wanting to start an alarm.
Definition Alarmable.cpp:101
@ ALARM_0
Definition AlarmableManager.h:15
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
static Panel * CreatePanel(int x, int y, Vect bkgColor=Vect(0, 0, 0, 0), Vect borderColor=Vect(0, 0, 0, 0))
Creates a panel for extra screen logging tools.
Definition ScreenLog.h:102
static void RemovePanel(Panel *p)
Removes a panel from rendering and deletes Panel.
Definition ScreenLog.h:108
static void Add(char *A,...)
Adds a new line to the top left Screen Logger.
Definition ScreenLog.cpp:49
static float GetFrameTime()
Returns Time Passed since Last Frame.
Definition TimeManager.h:66
void SubmitRegistration()
Called when wanting to make changes every frame.
Definition Updatable.cpp:37
static const Vect Blue
Definition ColorsCommon.h:28
static const Vect Red
Definition ColorsCommon.h:132