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 |
#include "Player.hpp" #include "Asteroid.hpp" |
Quellcode |
|
1 2 3 4 5 6 7 8 |
--------------------Konfiguration: SDL_Game - Win32 Debug-------------------- Kompilierung läuft... Game.cpp c:\projekte\spielms\game.cpp(53) : error C2601: 'RenderText' : Lokale Funktionsdefinitionen sind unzulaessig main.cpp Fehler beim Ausführen von cl.exe. SDL_Game.exe - 1 Fehler, 0 Warnung(en) |
Zitat von »"KeksX"«
Vielleicht hat sich irgendwo ein ";"-Fehler eingeschlichen...
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void CText::RenderText (const char *Text) { SDL_Color m_Color = {0,0,0}; SDL_Surface *TextToRender = NULL; // Text, der später gerendert wird TextToRender = TTF_RenderText_Solid(m_pFont, Text, m_Color); SDL_BlitSurface(TextToRender, NULL, m_pScreen, &m_Pos); } // RenderText // Spiel läuft m_bGameRun = true; } // Init[ |
C-/C++-Quelltext |
|
1 |
} // RenderText
|
Zitat
Sehe grade, das eine geschweifte Klammer zu viel ist.
C-/C++-Quelltext |
|
1 |
// Init[
|
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_HP #include "Framework.hpp" #include "SDL_ttf.h" class CText { public: CText (); ~CText (); void RenderText (const char *Text, int XPos, int YPos); void RenderText (const char *Text, int Color_R, int Color_G, int Color_B, int XPos, int YPos); /*void RenderText (const char *Text, int Color_R, int Color_G, int Color_B, int XPos, int YPos, const char *FontName, int Fontsize);*/ private: SDL_Surface *m_pScreen; // Zeiger auf den Screen des Frameworks SDL_Surface *m_pText; // Zeiger auf den Text, der anzuzeigen ist SDL_Color m_Color; // Farbe des Textes SDL_Color m_BackgroundColor; // Farbe des Hintergrundes TTF_Font *m_pFont; // Zeiger auf die Schriftart SDL_Rect m_Rect; // Rect des Textes }; #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 |
#include "Text.hpp" //CText // //Aufgabe: Screen-Pointer übergeben // CText::CText () { m_pScreen = g_pFramework->GetScreen (); TTF_Init (); m_pFont = TTF_OpenFont("Data/KingArthur.ttf", 28); //Da musst du DEIN (!!) Font reintun... } // CText CText::~CText () { TTF_CloseFont(m_pFont); TTF_Quit (); } // RenderText // // Aufgabe: Text auf den Bildschirm ausgeben (Standard) // void CText::RenderText (const char *Text, int XPos, int YPos) { m_Rect.x = XPos; m_Rect.y = YPos; SDL_Color m_Color = {255, 255, 255}; SDL_Surface *TextToRender = NULL; // Text, der später gerendert wird TextToRender = TTF_RenderText_Solid (m_pFont, Text, m_Color); SDL_BlitSurface(TextToRender, NULL, m_pScreen, &m_Rect); } // RenderText void CText::RenderText(const char *Text, int Color_R, int Color_G, int Color_B, int XPos, int YPos) { m_Rect.x = XPos; m_Rect.y = YPos; SDL_Color m_Color = {Color_R, Color_G, Color_B}; SDL_Surface *TextToRender = NULL; TextToRender = TTF_RenderText_Solid (m_pFont, Text, m_Color); SDL_BlitSurface (TextToRender, NULL, m_pScreen, &m_Rect ); } /*void CText::RenderText(const char *Text, int Color_R, int Color_G, int Color_B, int XPos, int YPos, const char *FontName, int Fontsize) { TTF_CloseFont (m_pFont); TTF_Init(); m_pFont = TTF_OpenFont (FontName, Fontsize); m_Rect.x = XPos; m_Rect.y = YPos; SDL_Color m_Color = {Color_R, Color_G, Color_B}; SDL_Surface *TextToRender = NULL; TextToRender = TTF_RenderText_Solid (m_pFont, Text, m_Color); SDL_BlitSurface (TextToRender, NULL, m_pScreen, &m_Rect ); } */ |
C-/C++-Quelltext |
|
1 2 3 4 |
#include "Text.hpp" //muss oben zu den anderen includes CText *m_pText; //Zeiger auf die CText Klasse //muss zu den private Variablen |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
m_pText = NULL; // im Konstruktor CGame::CGame() //Instanz eines Textes m_pText = new CText ; // in der Init Funktion von CGame if (m_pText != NULL) //das in die Quit Funktion von CGame { delete (m_pText); m_pText = NULL; } //Beliebigen Text rendern m_pText->RenderText("Hier dein Text", 173, 18, 211, 600, 30); //Das in die Run-Funktion von CGame |
Zitat von »"JoNnY"«
Du kennst dich ja besser aus.
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
void CText::RenderText(const char *Text, int Color_R, int Color_G, int Color_B, int XPos, int YPos, const char *FontName, int Fontsize) { TTF_CloseFont (m_pFont); TTF_Init(); m_pFont = TTF_OpenFont (FontName, Fontsize); } |
Werbeanzeige