Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Treue Seele
C-/C++-Quelltext |
|
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 |
CSprite *CText::Text(int Size, SDL_Color Color, const char *Text) { CSprite *pSprite; SAFE_DELETE(m_pfont); m_pfont = TTF_OpenFont("Data/ARIAL.TTF", Size); SDL_Color foregroundColor = Color; SDL_Color backgroundColor; backgroundColor.r = (Uint8)255; //Hier macht er aus Uint8 einen unsigned char, keine Ahnung weshalb backgroundColor.b = (Uint8)220; //und hier auch. backgroundColor.g = (Uint8)210; //und hier. SDL_Surface* textSurface = TTF_RenderText_Shaded(m_pfont, Text, foregroundColor, backgroundColor); //Hier liefert er "NULL" zurück. if(textSurface != NULL) pSprite->m_pImage = textSurface; else //"else" tritt ein. { g_pLogfile->Textout(1, "<b>Error: couldn't render \"textSurface\" (CText)</b></br>"); return 0; } pSprite->m_Rect.h = pSprite->m_pImage->h; pSprite->m_Rect.w = pSprite->m_pImage->w; pSprite->m_Rect.x = 0; pSprite->m_Rect.y = 0; pSprite->m_pScreen = g_pFramework->GetScreen(); if(!textSurface) { g_pLogfile->Textout(1, "<b>Error: couldn't render \"textSurface\" (CText)</b></br>"); return 0; } else { SDL_FreeSurface( textSurface ); } return( pSprite ); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
// SetColorKey // // Aufgabe: Transparente Farbe festlegen // void CSprite::SetColorKey (int R, int G, int B) { // Colorkey einstellen SDL_SetColorKey (m_pImage, SDL_SRCCOLORKEY, SDL_MapRGB (m_pImage->format, R, G, B) ); } // SetColorKey |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
void CHud::InitSprite( CSprite *pSprite, const char *Text, int X, int Y) { pSprite = g_pText->Text(Text); pSprite->m_Rect.x = X; pSprite->m_Rect.y = Y; pSprite->SetPos( static_cast<float> ( X ), static_cast<float> ( Y )); pSprite->SetColorKey( 255, 220, 210); } |
Treue Seele
C-/C++-Quelltext |
|
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 |
#ifndef TEXT_HPP #define TEXT_HPP #include "Framework.hpp" #include <string> #include <SDL_ttf.h> class CText { public: CText(const string Filename,const int Size); ~CText(); void Load(const string Filename,const int Size);//Zum Laden des Fonts void SetColor(int R,int G,int B);//Farben setzen void SetPos(int X,int Y);//Koordinaten setzen void Render();//Rendern void SetText(string TextTemp);//den Text setzen private: void Update(); CText(const CText &TempCText); SDL_Surface *Surface;//Der echte Surface SDL_Surface *SurfaceText; SDL_Color Text_color;//Farbe des Textes SDL_Rect Rect;//Koordinaten des Textes string Text;//der Text TTF_Font *Font;//Font + Größe }; #endif |
Dieser Beitrag wurde bereits 7 mal editiert, zuletzt von »dot« (21.10.2010, 16:35)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
void CText::RenderText( char *Filename, char *Text,int Size, int X, int Y) { SetText(Text); //das gibt n error Load(Filename, Size); //das macht auch n error SetPos(X, Y); // da gibt's auch n error SetTextColor(Black); //da auch Render(); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void CText::Render() { m_pScreen = g_pFramework->GetScreen(); SDL_Surface *Surf = TTF_RenderText_Blended(m_pFont, m_Text, m_TextColor); //Hier gibt's auch ne Zugriffsverletzung SDL_FillRect(m_pTextSurface,NULL, (SDL_MapRGB (m_pScreen->format, Score.r, Score.g, Score.b))); SDL_BlitSurface(Surf, NULL, m_pTextSurface, NULL); SDL_BlitSurface(m_pTextSurface, NULL, m_pScreen, &m_Rect); SDL_FreeSurface(m_pTextSurface); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
void CText::SetTextColor( int R, int G, int B ) { m_TextColor.r = R; //Zugriffsverletzung m_TextColor.g = G; //hier auch m_TextColor.b = B; //und hier auch } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »RmbRT« (21.10.2010, 19:11)
Treue Seele
C-/C++-Quelltext |
|
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 |
#include "Text.hpp" CText::CText(const string Filename,const int Size) { Surface=g_pFramework->GetScreen(); Text=std::string(" "); SDL_Color Temp={1,1,1}; Text_color=Temp; Rect.x=Rect.y=Rect.h=Rect.w=0; Font = TTF_OpenFont(Filename.c_str(), Size); SurfaceText = TTF_RenderText_Blended(Font,Text.c_str(),Text_color); } CText::~CText() { SDL_FreeSurface (Surface); SDL_FreeSurface (SurfaceText); } void CText::Load(const string Filename,const int Size) { Font = TTF_OpenFont(Filename.c_str(), Size); Update(); } void CText::SetColor(int R,int G,int B) { SDL_Color Temp={R,G,B}; Text_color=Temp; Update(); } void CText::SetPos(int X,int Y) { Rect.x=X; Rect.y=Y; Rect.h=Rect.w=1; Update(); } void CText::SetText(string TextTemp) { Text=TextTemp; Update(); } void CText::Render() { if ((SDL_BlitSurface(SurfaceText , NULL, Surface, &Rect )!= 0)) { cerr << "SDL_BlitSurface() Failed: " << SDL_GetError() << endl; } } void CText::Update() { SDL_FreeSurface(SurfaceText); SurfaceText = TTF_RenderText_Blended(Font,Text.c_str(),Text_color); } |
C-/C++-Quelltext |
|
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 |
void CHud::InitSprite( CText *pText, string Text, int X, int Y) { pText->CreateText("ARIAL.TTF", 24, 255, 255, 0, Text); } void CHud::UpdateSprites() { char *Lifes = " "; char *Score = " "; char *Level = " "; char *Money = " "; char *CreepHP = " "; //ERROR sprintf( Lifes, "Lifes: %i", g_pGame->m_Lives ); sprintf( Score, "Score: %i", (g_pGame->m_Lives * g_pGame->m_Level)); sprintf( Level, "Level: %i", g_pGame->m_Level); sprintf( Money, "Money: %i", g_pGame->m_Money ); sprintf( CreepHP, "Creep HP: %i", g_pGame->m_HP); InitSprite( m_pLifes, Lifes, 820, 60); InitSprite( m_pScore, Score, 820, 160); InitSprite( m_pLevel, Level, 820, 260); InitSprite( m_pMoney, Money, 820, 360); InitSprite( m_pCreepHP, CreepHP, 820, 460); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
void CText::CreateText(const string Filename, const int Size, int R, int G, int B, string TempText) { Load(Filename, Size); SetColor( R, G, B); SetPos( 0, 0 ); SetText(TempText); Render(); } |
Quellcode |
|
1 |
char* blubb = " "; |
Quellcode |
|
1 |
std::string livesText = boost::lexical_cast<std::string> (g_pGame->m_Lives); |
Werbeanzeige