Splash screen loads and displays correctly

This commit is contained in:
Kayne Ruse
2013-06-12 19:15:37 +10:00
parent cbd388f4ed
commit f3ec4d4d8e
3 changed files with 52 additions and 46 deletions
+4
View File
@@ -137,6 +137,10 @@ void SceneManager::Proc() {
void SceneManager::Quit() { void SceneManager::Quit() {
//clean up the services //clean up the services
netUtil->Close();
surfaceMgr->FreeAll();
//delete the services
configUtil = ServiceLocator<ConfigUtility>::Set(nullptr); configUtil = ServiceLocator<ConfigUtility>::Set(nullptr);
surfaceMgr = ServiceLocator<SurfaceManager>::Set(nullptr); surfaceMgr = ServiceLocator<SurfaceManager>::Set(nullptr);
netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr); netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr);
+33 -37
View File
@@ -12,9 +12,11 @@ SplashScreen::SplashScreen() {
#ifdef DEBUG #ifdef DEBUG
cout << "entering SplashScreen" << endl; cout << "entering SplashScreen" << endl;
#endif #endif
logo.SetSurface(surfaceMgr->Load("splash-logo", configUtil->String("logos") + "/krstudios.bmp"));
} }
SplashScreen::~SplashScreen() { SplashScreen::~SplashScreen() {
surfaceMgr->Free("splash-logo");
#ifdef DEBUG #ifdef DEBUG
cout << "leaving SplashScreen" << endl; cout << "leaving SplashScreen" << endl;
#endif #endif
@@ -24,46 +26,40 @@ SplashScreen::~SplashScreen() {
//Frame loop //Frame loop
//------------------------- //-------------------------
void SplashScreen::FrameStart() { void SplashScreen::RunFrame(double delta) {
// HandleEvents();
if (!loaded) {
//never repeat this
loaded = true;
//quick draw
RenderFrame();
LoadResources();
} }
void SplashScreen::Update(double delta) { if (Clock::now() - start > std::chrono::duration<int>(1)) {
// SetNextScene(SceneList::MAINMENU);
}
void SplashScreen::FrameEnd() {
//
}
void SplashScreen::Render(SDL_Surface* const screen) {
//
}
//-------------------------
//Event handlers
//-------------------------
void SplashScreen::MouseMotion(SDL_MouseMotionEvent const& motion) {
//
}
void SplashScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) {
//
}
void SplashScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//
}
void SplashScreen::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
} }
} }
void SplashScreen::KeyUp(SDL_KeyboardEvent const& key) { void SplashScreen::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0);
int x = (GetScreen()->w - logo.GetClipW()) / 2;
int y = (GetScreen()->h - logo.GetClipH()) / 2;
logo.DrawTo(GetScreen(), x, y);
SDL_Flip(GetScreen());
}
void SplashScreen::LoadResources() {
//standard
surfaceMgr->Load("font", configUtil->String("fonts") + "/pokemon_dark_font.bmp");
surfaceMgr->Load("button", configUtil->String("interface") + "/button.bmp");
//debugging
surfaceMgr->Load("elliot", configUtil->String("sprites") + "/elliot2.bmp");
surfaceMgr->Load("coa", configUtil->String("sprites") + "/coa2.bmp");
surfaceMgr->Load("flower", configUtil->String("sprites") + "/aniflower.bmp");
surfaceMgr->Load("terrain", configUtil->String("tilesets") + "/terrain.bmp");
//TODO
} }
+16 -10
View File
@@ -2,6 +2,14 @@
#define SPLASHSCREEN_HPP_ #define SPLASHSCREEN_HPP_
#include "base_scene.hpp" #include "base_scene.hpp"
#include "service_locator.hpp"
#include "defines.hpp"
#include "config_utility.hpp"
#include "surface_manager.hpp"
#include "image.hpp"
#include <chrono>
class SplashScreen : public BaseScene { class SplashScreen : public BaseScene {
public: public:
@@ -11,17 +19,15 @@ public:
protected: protected:
/* Frame loop */ /* Frame loop */
void FrameStart(); void RunFrame(double delta);
void Update(double delta); void RenderFrame();
void FrameEnd(); void LoadResources();
void Render(SDL_Surface* const);
/* Event handlers */ bool loaded = false;
void MouseMotion(SDL_MouseMotionEvent const&); ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
void MouseButtonDown(SDL_MouseButtonEvent const&); SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
void MouseButtonUp(SDL_MouseButtonEvent const&); Image logo;
void KeyDown(SDL_KeyboardEvent const&); Clock::time_point start = Clock::now();
void KeyUp(SDL_KeyboardEvent const&);
}; };
#endif #endif