1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// Constructor
//
// Purpose: Get Pointer to Renderer
//
C_Sprite::C_Sprite()
{
m_pRenderer = g_pFramework->Get_Renderer();
}// Constructor
// Destructor
//
// Purpose: Terminate Sprite
//
C_Sprite::~C_Sprite()
{
SDL_DestroyTexture(m_pImage);
}// Destructor
// Display Text (fixed position)
//
// Purpose: Display Text on the Screen
//
void C_Sprite::Display_Text(const std::string sFont, const std::string sText, int Size, float fX_Position, float fY_Position, int R, int G, int B)
{
TTF_Font * pFont = TTF_OpenFont(sFont.c_str(), Size);
SDL_Color Color = { R, G, B };
SDL_Surface * pTemp = TTF_RenderText_Solid(pFont, sText.c_str(), Color);
m_pImage = SDL_CreateTextureFromSurface(m_pRenderer, pTemp); // generate the actual sprite/texture that the renderer can then display on the screen
// Initialize Rect
//
m_Rect.w = pTemp->w; // get width for rectangle from pTemp (of type "SDL_Surface")
m_Rect.h = pTemp->h; // get height for rectangle from pTemp (of type "SDL_Surface")
m_Rect.x = static_cast<int>(fX_Position); // set x position relative to size of rect (since we are talking about text, the size can vary)
m_Rect.y = static_cast<int>(fY_Position); // set x position relative to size of rect (since we are talking about text, the size can vary)
TTF_CloseFont(pFont); // close font to free memory
SDL_FreeSurface(pTemp); // clear temporary surface
}// Display Text (fixed position)
// Render (static)
//
// Purpose: Render static Sprite
//
void C_Sprite::Render()
{
// Render Sprite
//
SDL_RenderCopy(m_pRenderer, m_pImage, NULL, &m_Rect);
}// Render (static)
|