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 21 22 23 24 25 |
#ifndef CPOINTS_HPP #define CPOINTS_HPP #include <SDL.h> #include <SDL_ttf.h> #include <stdlib.h> #include <string.h> class CPoints { public: int Init (); void Quit (); //void Update (); void Render (); int GetPoints (); void Increase(int by_x); private: int m_Points; TTF_Font *m_font; SDL_Surface *glyph,*screen; }; #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 60 61 62 63 64 65 |
#include "CPoints.hpp" int CPoints::Init() { m_Points=0; if(TTF_Init()==-1)//Initialisiere Fonts { printf("TTF_Init: %s\n", TTF_GetError()); return(2); } m_font=TTF_OpenFont("Data/font.ttf", 10);//Lade font.ttf font size=10 if(!m_font) { printf("TTF_OpenFont: %s\n", TTF_GetError()); }// handle error TTF_ByteSwappedUNICODE(1); return(0); } void CPoints::Quit () { TTF_CloseFont(m_font); m_font=NULL; // to be safe... TTF_Quit(); } // Quit /* void CPoints::Update() { Points=GetPoints(); } */ void CPoints::Render() { int X=0; int Y=0; char output[64]; sprintf(output,"%i",m_Points); SDL_Color color={0,0,0}; SDL_Surface *text_surface; if(!(text_surface=TTF_RenderText_Solid(m_font,"Hello World!",color))) { //handle error here, perhaps print TTF_GetError at least } else { SDL_BlitSurface(text_surface,NULL,screen,NULL); //perhaps we can reuse it, but I assume not for simplicity. SDL_FreeSurface(text_surface); } } int CPoints::GetPoints () { return m_Points; } void CPoints::Increase(int by_x) { m_Points+=by_x; } |
Anonymous
unregistriert
Zitat von »"scarsen"«
Hi!
Wie initialisierst du denn die Membervariable "screen"? Sie ist private -
d.h. es müsste eine Methode "setScreenSurface(Screen * s)" oder so
geben. Da es diese aber nicht gibt vermute ich, dass screen uninitialisiert
ist. Dann müsste daher der Fehler kommen...
Zitat
SDL_BlitSurface(text_surface,NULL,g_pFramework->m_pScreen,NULL);
Werbeanzeige