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 26 27 28 29 30 31 32 33 34 |
#pragma once #include <SFML\Graphics.hpp> #include "Ball.hpp" using namespace sf; using namespace std; class CFramework { public: CFramework (int WindowWidth, int WindowHeight, string Title); void Run (); private: void Update (float ElapsedTime); void Render (); void HandleEvents (); void Quit (); float GetElapsedTime (); RenderWindow Window; Event Event; Clock Clock; CBall Ball(string("Assets/Ball.png"), Vector2f(400, 300)); float ElapsedTime; bool Running; }; |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »N4SONIC« (27.12.2015, 00:25)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
CFramework::CFramework(int WindowWidth, int WindowHeight, string Title) : Ball(string("Assets/Ball.png"), Vector2f(400, 300)), // Ball initialisieren (wird den passenden Konstruktor aufrufen) ElapsedTime(0.0f), // ElapsedTime initialisieren Running(false) // Running initialiieren { // für Window, Event und Clock wurde der Default Konstruktor aufgerufen } |
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 66 67 |
#include "Framework.hpp" CFramework::CFramework(int WindowWidth, int WindowHeight, string Title) : Running(true) { Window.create(VideoMode(WindowWidth, WindowHeight), Title.c_str(), Style::Titlebar | Style::Close); } void CFramework::Run() { while (Running) { Update(ElapsedTime); Render(); HandleEvents(); Quit(); GetElapsedTime(); } } void CFramework::Update(float ElapsedTime) { } void CFramework::Render() { Window.clear(); Window.display(); } void CFramework::HandleEvents() { while (Window.pollEvent(Event)) { if (Event.type == Event::Closed) { Running = false; } } } void CFramework::Quit() { if (Running == false) { Window.close(); } } float CFramework::GetElapsedTime() { ElapsedTime = Clock.getElapsedTime().asSeconds(); Clock.restart(); return ElapsedTime; } |
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 66 67 68 69 70 |
#include "Framework.hpp" CFramework::CFramework(int WindowWidth, int WindowHeight, string Title) : Running(true), Ball(string("Assets/Ball.png"), Vector2f(400, 300)) { Window.create(VideoMode(WindowWidth, WindowHeight), Title.c_str(), Style::Titlebar | Style::Close); } void CFramework::Run() { while (Running) { Update(ElapsedTime); Render(); HandleEvents(); Quit(); GetElapsedTime(); } } void CFramework::Update(float ElapsedTime) { Ball.Update(ElapsedTime); } void CFramework::Render() { Window.clear(); Ball.Render(Window); // <--- Problem !! Window.display(); } void CFramework::HandleEvents() { while (Window.pollEvent(Event)) { if (Event.type == Event::Closed) { Running = false; } } } void CFramework::Quit() { if (Running == false) { Window.close(); } } float CFramework::GetElapsedTime() { ElapsedTime = Clock.getElapsedTime().asSeconds(); Clock.restart(); return ElapsedTime; } |
Werbeanzeige