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
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#ifndef FONT_HPP #define FONT_HPP #include <SDL_ttf.h> class CFont { public: void init(); void init( const char *fontName, int size); void setFont( TTF_Font *font); void write(SDL_Surface *surface, const char *text, SDL_Color color); void write(const char *text, SDL_Color color); ~CFont(); private: TTF_Font *m_font; // Font-Datei SDL_Surface *m_surface; // Auf dieses Surface wird dann geschrieben... }; #endif |
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 |
#include "Font.hpp" #include <iostream> #include <SDL_ttf.h> using namespace std; //Init: SDL_ttf laden und initialisieren, parameterlos void CFont::init() { //Initialisierung: SDL_ttf if(TTF_Init() == -1 ) { cout << "SDL_ttf konnte nicht initialisiert werden!" << endl; cout << "Fehlermeldung:"<< SDL_GetError(); } }//Init //Init..mit Parametern void CFont::init( const char *fontName, int size) { init(); //Normale SDL_ttf initialisierung //Schriftart laden m_font = TTF_OpenFont(fontName, size); if(!m_font) { cout << "Laden der Schriftart <"<< fontName << "> fehlgeschlagen!"<< endl; cout << "Fehlermeldung:" << SDL_GetError() << endl; } }//Init //Destruktor CFont::~CFont() { if(m_surface != NULL) { delete(m_surface); m_surface = NULL; } }//Desktruktor //Write: Text auf das Surface schreiben void CFont::write(SDL_Surface *surface, const char *text, SDL_Color color) { if(!(surface=TTF_RenderText_Solid(m_font, text, color))) { cout << "Fehler beim schreiben auf das Surface!" << endl; cout << "Fehlermeldung: " << SDL_GetError() << endl; } }//write void CFont::write(const char *text, SDL_Color color) { write(m_surface, text, color); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
SDL_Color color; color.r = 255; color.g = 0; color.b = 255; m_font.init( "ariblk.ttf", 40); m_font.write(g_pFramework->getScreen(), "BLUBB", color); |
C-/C++-Quelltext |
|
1 |
SDL_BlitSurface (surface, NULL, g_pFramework->getScreen(), NULL); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void CFont::Write (char cText[]) { SDL_Color textColor = {0, 0, 0}; SDL_Surface *NewText; NewText = TTF_RenderText_Solid (m_Font, cText, textColor); SDL_BlitSurface (NewText, NULL, g_pFramework->GetScreen (), NULL); SDL_FreeSurface(NewText); } |
Zitat von »"Schnitter"«
Geil
Kleine Zwischenfrage: Wäre es eine gute Idee, die Font-Klasse als Singleton zu implementieren? Oder eher schlecht?
Zitat von »"Dofter"«
Ich würde kein Singleton benutzen, weil wenn ich dass so richtig sehe, man pro Instanz immer nur eine Schriftart laden kann. D.h. Singleton => nur eine Schriftart - kein Singleton => meherer Schriftarten möglich
Zitat
Sound.obj : error LNK2001: Nichtaufgeloestes externes Symbol _Mix_OpenAudio
Sound.obj : error LNK2001: Nichtaufgeloestes externes Symbol _Mix_CloseAudio
Sound.obj : error LNK2001: Nichtaufgeloestes externes Symbol _Mix_FreeChunk
Sound.obj : error LNK2001: Nichtaufgeloestes externes Symbol _Mix_PlayChannelTimed
Sound.obj : error LNK2001: Nichtaufgeloestes externes Symbol _Mix_LoadWAV_RW
Zitat
*.dll im projekt-ordner?
/edit: bzw. die *.lib in den projekt-optionen?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
void CSound::playSound(char soundFileName[])//Must be a *.wav file! { // Sound laden m_pSound = Mix_LoadWAV( soundFileName ); //Sound abspielen Mix_PlayChannel(-1, m_pSound, 0); }//playSound |
C-/C++-Quelltext |
|
1 2 3 4 5 |
void CSound::playSound(Mix_Chunk* pSound) { //Sound abspielen Mix_PlayChannel(-1, pSound, 0); }//playSound |
C-/C++-Quelltext |
|
1 |
m_pExplosionSound = Mix_LoadWAV("Data/explosion.wav"); |
Werbeanzeige