diff --git a/src/game.cc b/src/game.cc index b6f8232..f21d1c2 100644 --- a/src/game.cc +++ b/src/game.cc @@ -48,7 +48,6 @@ Game::Game(SDL2pp::Renderer& renderer) tile_cache_(renderer), session_start_(std::chrono::steady_clock::now()), coins_(coin_locations_) { - tile_cache_.PreloadTilesSync(GetCameraRect()); } Game::~Game() { @@ -110,6 +109,10 @@ SDL2pp::Rect Game::GetCoinRect(const SDL2pp::Point& coin) const { ); } +void Game::LoadVisibleTiles() { + tile_cache_.PreloadTilesSync(GetCameraRect()); +} + void Game::Update(float delta_t) { // All original game constants work at 60 fps fixed frame // rate and do not take real frame time into account, so diff --git a/src/game.hh b/src/game.hh index 40594e4..1d4b129 100644 --- a/src/game.hh +++ b/src/game.hh @@ -152,6 +152,7 @@ public: SDL2pp::Rect GetPlayerCollisionRect() const; SDL2pp::Rect GetCoinRect(const SDL2pp::Point& coin) const; + void LoadVisibleTiles(); void Update(float delta_t); void Render();//const SDL2pp::Rect& viewport); diff --git a/src/main.cc b/src/main.cc index ffefdfb..180805e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -85,6 +85,12 @@ int main(int /*argc*/, char** /*argv*/) try { game.ClearActionFlag(Game::DOWN); break; } + } else if (event.type == SDL_WINDOWEVENT) { + switch (event.window.event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + game.LoadVisibleTiles(); + break; + } } }