Ketchup Engine
Loading...
Searching...
No Matches
Getting Started - Creating a Scene

Creating a Scene

Header

To set up a scene for our game, we'll have to create a class for it which inherits from Scene. Scene has the methods Scene::Init() and Scene::End() for us to override. These methods are called by the SceneManager to set up and clean up our scene.

#include "Scene.h"

class DemoScene : public Scene
{
public:

    DemoScene();
    DemoScene(const DemoScene&) = delete;
    DemoScene& operator = (const DemoScene&) = delete;
    ~DemoScene();

private:

    void Init() override;
    void End() override;

};

Init()

Scene::End() is where we will do any setup and registration of GameObjects for the scene, but for now we can leave it mostly empty. We'll just set up our camera, though there's nothing for us to render yet.

void DemoScene::Init()
{
    SceneManager::GetCurrentScene()->GetMainCam()->setOrientAndPosition(Vect(0, 1, 0), Vect(), Vect(0, 100, 100));
}

End()

Scene::End() is where we will do any cleanup and deregistration of GameObjects for the scene, but for now we can leave it empty.

Setting a Start Scene

We can also go back to our LoadResources method and set the start scene to be our scene. Note that SceneManager handles memory cleanup for any scene that it manages.

#include "DemoScene.h"
#include "SceneManager.h"

void GameSettings::LoadResources()
{
    [...]

    SceneManager::SetStartScene(new DemoScene());
}

See Loading Assets.

A Blank Window!

Now, if we start the game, we'll have a completely empty scene!