jade-engine  0.0
JadeEngine::IScene Class Reference

#include <IScene.h>

Inheritance diagram for JadeEngine::IScene:
JadeEngine::MainMenuScene JadeEngine::OptionsMenuScene JadeEngine::PoweredByJadeEngineScene

Public Member Functions

virtual void SpriteHovered (Sprite *oldSprite, Sprite *newSprite)
 
virtual void Start ()
 
virtual void PreUpdate ()
 
virtual void Update ()
 
bool GetInitialized () const
 
void SetInitialized (const bool initialized)
 
bool GetActive () const
 
void SetActive (const bool active)
 

Detailed Description

Interface for Scene classes.

Scene is a high-level building block of a game in Jade engine. It is a collection of game objects that are updated and rendered at the same time, and usually contains logic that operates on those game objects.

All game objects created while a scene is active, such as during it's Start() function will be considered part of that scene and will stop being updated and rendered when a new scene is played. Exception to that are objects created with kObjectLayer_Persistent_UI ObjectLayer which are always rendered and updated.

All scenes must inherit from IScene and can override the public virtual functions in order receive callbacks from the Jade engine.

See also
Game::AddScene, Game::PlayScene

Template for new scene:

#include "IScene.h"
using namespace JadeEngine;
class GameScene : public IScene
{
public:
void Start() override;
void Update() override;
};

Member Function Documentation

◆ GetActive()

bool JadeEngine::IScene::GetActive ( ) const
inline

Returns whether this scene is currently active, i.e. its Update() is being called every frame.

◆ GetInitialized()

bool JadeEngine::IScene::GetInitialized ( ) const
inline

Returns whether this scene was already initialized, i.e. its Start() was already called.

◆ PreUpdate()

virtual void JadeEngine::IScene::PreUpdate ( )
inlinevirtual

Triggered ever frame by the Jade Engine while this scene is active.

To obtain delta time since last frame use GTime.deltaTime.

The trigger order is the following: IScene::PreUpdate -> IGameObject::Load -> IGameObject::Update -> IScene::Update -> IGameObject::Load -> IGameObject::Render.

See also
Game::PlayScene, Time, IGameObject::Update

◆ SetActive()

void JadeEngine::IScene::SetActive ( const bool  active)
inline

Set this scene as active, i.e. its Update() will being called every frame.

Warning
Used internally by the Jade Engine and there is very little reason to call this as a user.

◆ SetInitialized()

void JadeEngine::IScene::SetInitialized ( const bool  initialized)
inline

Set this scene as initialized, i.e. next GGame.PlayScene will now longer trigger Start().

Warning
Used internally by the Jade Engine and there is very little reason to call this as a user.

◆ SpriteHovered()

virtual void JadeEngine::IScene::SpriteHovered ( Sprite oldSprite,
Sprite newSprite 
)
inlinevirtual

Triggered when a new Sprite was hovered over by mouse while this scene is active.

Parameters
oldSpritePreviously hovered Sprite or nullptr if no Sprite was previously hovered.
newSpriteNewly hovered Sprite.
See also
Game::GetHoveredSprite

◆ Start()

virtual void JadeEngine::IScene::Start ( )
inlinevirtual

Triggered the first time this scene is played.

An ideal callback to initialize the scene's game objects. Only triggered once, i.e. second call to GGame.PlayScene with this scene will not trigger Start(). Start() will be triggered immediately when GGame.PlayScene is called while the first Update() will happen next frame.

See also
Game::PlayScene
void GameScene::Start() //override
{
// Assuming GameScene has `Button* _button` and `float _timer` members and we have filled `ButtonParams buttonParams` variable.
_button = GGame.Create<Button>(buttonParams);
_timer = 5.0f;
}

Reimplemented in JadeEngine::OptionsMenuScene, JadeEngine::MainMenuScene, and JadeEngine::PoweredByJadeEngineScene.

◆ Update()

virtual void JadeEngine::IScene::Update ( )
inlinevirtual

Triggered every frame by the Jade Engine while this scene is active.

To obtain delta time since last frame use GTime.deltaTime.

The trigger order is the following: IScene::PreUpdate -> IGameObject::Load -> IGameObject::Update -> IScene::Update -> IGameObject::Load -> IGameObject::Render.

See also
Game::PlayScene, Time, IGameObject::Update
#include "Button.h"
#include "EngineTime.h"
void GameScene::Update() //override
{
// Assuming we have created a Button in the scene's Start() callback
if (_button->Released())
{
// Button was pressed, do something
}
// Assuming the scene contains `float _timer` member variable initialized to certain amount of time in seconds
_timer -= GTime.deltaTime;
if (_timer < 0.0f)
{
// Timer expired, do something
}
}

Reimplemented in JadeEngine::OptionsMenuScene, JadeEngine::MainMenuScene, and JadeEngine::PoweredByJadeEngineScene.


The documentation for this class was generated from the following file:
JadeEngine::IScene
Definition: IScene.h:33
JadeEngine::Game::Create
std::add_pointer_t< Class > Create(const CreationStruct &params)
Definition: Game.h:299
JadeEngine::IScene::Start
virtual void Start()
Definition: IScene.h:60
JadeEngine::IScene::Update
virtual void Update()
Definition: IScene.h:103