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
Du musst sie ständig updaten bzw. die Texture neu erstellen, sofern der Punktestand mit dem vorherigen nicht übereinstimmt, ja.
Aber dann wäre es doch einfacher, das Updaten genau dann durchzuführen, wenn die Punktezahl aktualisiert wurde.
Zitat
Du musst sie ständig updaten bzw. die Texture neu erstellen, sofern der Punktestand mit dem vorherigen nicht übereinstimmt, ja.
Alles klar. Braucht dies nicht massiv viel Speicher? Ich müsste doch die alten Texturen dann irgendwie wieder löschen?
Du musst sie ständig updaten bzw. die Texture neu erstellen, sofern der Punktestand mit dem vorherigen nicht übereinstimmt, ja.
Aber dann wäre es doch einfacher, das Updaten genau dann durchzuführen, wenn die Punktezahl aktualisiert wurde.
Richtig.
Zitat
Du musst sie ständig updaten bzw. die Texture neu erstellen, sofern der Punktestand mit dem vorherigen nicht übereinstimmt, ja.
Deswegen muss [...] jedesmal eine erneute SDL_Texture aus der durch SDL_TTF generierten SDL_Surface erzeugt werden. Aber um zumindest ein wenig neu Erzeugung zu sparen, sollte man schon prüfen, ob sich der Punktestand verändert hat.
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
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 |
while(bGameRun == true) { SDL_RenderClear(r_pRenderer); sBackground->Render("Hintergrund", 0, 0, 800, 600, r_pRenderer); Field->Choose(); Field->Render(); Field->Update(); Field->CheckWin1(Player1); Field->CheckWin2(Player2); stringstream s; s << "Player 1: " << Player1; Spieler1->LoadText (s.str().c_str(), { 0, 0, 0 },".../AvenirNext.ttc", 20, "Player 1"); Spieler1->RenderText(40, 90, 120, 24, "Player 1"); stringstream b; b << "Player 2: " << Player2; Spieler2->LoadText (b.str().c_str(), { 0, 0, 0 },".../AvenirNext.ttc", 20, "Player 2"); Spieler2->RenderText(40, 120, 120, 24, "Player 2"); SDL_RenderPresent(r_pRenderer); if (g_pFramework->isKeyDown (SDL_SCANCODE_ESCAPE)) { bGameRun = false; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
if (textImage[id] != NULL) { SDL_DestroyTexture(textImage[id]); } else { } textImage[id] = textTexture; TTF_CloseFont(fFont); fFont = NULL; return true; |
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 |
bool CText::LoadText(string textureText, SDL_Color textColor, string fontFile, int fontSize, string id) { // Font wird geladen fFont = TTF_OpenFont(fontFile.c_str(), fontSize ); if( fFont == NULL ) { cout << "Font konnte nicht geladen werden: " << TTF_GetError () << endl; return false; } else { // Der Text wird auf eine Surface gerendert SDL_Surface* textSurface = TTF_RenderText_Blended(fFont, textureText.c_str(), textColor ); if( textSurface == NULL ) { cout << "Text Surface konnte nicht gerendert werden: " << SDL_GetError () << endl; return 0; } else { // Von Surface zu einer Texture textTexture = SDL_CreateTextureFromSurface(r_pRenderer, textSurface); if( textTexture == NULL ) { cout << "Text Template konnte nicht gerendert werden: " << SDL_GetError () << endl; return 0; } else { // Bild Dimension eintragen fWidth = textSurface->w; fHeight = textSurface->h; } // Alte Surface löschen SDL_FreeSurface( textSurface ); } } // Erfolg! if (textImage[id] != NULL) { SDL_DestroyTexture(textImage[id]); } else { } textImage[id] = textTexture; TTF_CloseFont(fFont); fFont = NULL; return true; } |
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 |
bool CText::LoadText(string textureText, SDL_Color textColor, string fontFile, int fontSize, string id) { // Font wird geladen if( fFont == nullptr ) { fFont = TTF_OpenFont(fontFile.c_str(), fontSize ); } else { } // Der Text wird auf eine Surface gerendert SDL_Surface* textSurface = TTF_RenderText_Blended(fFont, textureText.c_str(), textColor ); if( textSurface == nullptr ) { cout << "Text Surface konnte nicht gerendert werden: " << SDL_GetError () << endl; return 0; } else { // Von Surface zu einer Texture textTexture = SDL_CreateTextureFromSurface(r_pRenderer, textSurface); if( textTexture == nullptr ) { cout << "Text Template konnte nicht gerendert werden: " << SDL_GetError () << endl; return 0; } else { // Bild Dimension eintragen fWidth = textSurface->w; fHeight = textSurface->h; } // Alte Surface löschen SDL_FreeSurface( textSurface ); } // Erfolg! if (textImage[id] != nullptr) { SDL_DestroyTexture(textImage[id]); } else { } textImage[id] = textTexture; return true; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
if (textImage[id] != nullptr) { SDL_DestroyTexture(textImage[id]); } else { } |
Werbeanzeige