TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Game::GameScene Class Referenceabstract

#include <tb_game_scene.hpp>

Inheritance diagram for TurtleBrains::Game::GameScene:
TurtleBrains::Game::EntityManager TurtleBrains::Graphics::GraphicList TurtleBrains::Graphics::Graphic

Public Member Functions

 GameScene (void)
 
virtual ~GameScene (void)=0
 
- Public Member Functions inherited from TurtleBrains::Game::EntityManager
 EntityManager (void)
 
virtual ~EntityManager (void)=0
 
void ClearEntities (void)
 
void AddEntity (Entity *entity)
 
void AddEntity (Entity &entity)
 
void RemoveEntity (Entity *entity)
 
void RemoveEntities (const EntityType &byType=Entity::kInvalidType)
 
void EntityTypeChanged (Entity &entity, const EntityTypeContainer &oldTypes)
 
EntityList GetAllEntities (void)
 
EntityList GetEntitiesByType (const EntityType &byType)
 
EntityList GetEntitiesAt (const tbMath::Vector2 &point, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
 
EntityList GetEntitiesWithin (const tbMath::Vector2 &center, const float radius, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
 
EntityList GetEntitiesWithin (const tbMath::Vector2 &center, const float width, const float height, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
 
void Simulate (void)
 
- Public Member Functions inherited from TurtleBrains::Graphics::GraphicList
 GraphicList (void)
 
virtual ~GraphicList (void)
 
void ClearGraphics (void)
 
void AddGraphic (Graphic *graphic)
 
void AddGraphic (Graphic &graphic)
 
void RemoveGraphic (Graphic *graphic)
 
virtual void SetColor (const tbGraphics::Color &newColor) override
 
virtual PixelSpace GetPixelWidth (void) const
 
virtual PixelSpace GetPixelHeight (void) const
 
void RecalculateWidthAndHeight (void)
 
- Public Member Functions inherited from TurtleBrains::Graphics::Graphic
 Graphic (void)
 
 Graphic (const Graphic &other)
 
virtual ~Graphic (void)
 
bool IsActive (void) const
 
void SetActive (const bool isActive)
 
void Update (const float deltaTime)
 
bool IsVisible (void) const
 
void SetVisible (const bool isVisible)
 
void Render (void) const
 
const tbMath::Vector2GetPosition (void) const
 
void SetPosition (const float x, const float y)
 
void SetPosition (const tbMath::Vector2 &position)
 
const tbMath::Vector2GetOrigin (void) const
 
void SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
void SetOrigin (const float originX, const float originY)
 
void SetOrigin (const tbMath::Vector2 &origin)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
const tbMath::Vector2GetScale (void) const
 
void SetScale (const float scale)
 
void SetScale (const tbMath::Vector2 &scale)
 
void SetScale (const float scaleX, const float scaleY)
 
float GetRotation (void) const
 
void SetRotation (const float rotation)
 
void SetScroll (const float scroll)
 
void SetScroll (const float scrollX, const float scrollY)
 
bool IsRelative (void) const
 
const ColorGetColor (void) const
 
float GetWidth (void) const
 
float GetHeight (void) const
 
float GetScaledWidth (void) const
 
float GetScaledHeight (void) const
 
bool UnstableIsPointContained (const tbMath::Vector2 &point) const
 

Static Public Member Functions

static void ChangeToScene (GameScene &gameScene)
 
static void PerformFrame (const float deltaTime)
 
static void PerformFrame (GameScene &gameScene, const float deltaTime)
 

Protected Member Functions

virtual void OnSimulate (void)
 
virtual void OnUpdate (const float deltaTime)
 
virtual void OnRender (void) const
 
virtual void OnOpen (void)
 
virtual void OnClose (void)
 
virtual void OnRuntimeReload (void)
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Additional Inherited Members

- Public Types inherited from TurtleBrains::Game::EntityManager
typedef std::list< Entity * > EntityList
 

Detailed Description

The GameScene object can also be considered a game state, or screen which contains the logic of a small part of the game. Typically many GameScene will build the game, perhaps a TitleScene, OptionsScene, GameplayScene and CreditsScene. The GameScene provides an interface to override the behaviors as desired.

Constructor & Destructor Documentation

TurtleBrains::Game::GameScene::GameScene ( void  )

Initializes the accumulated simulation time to 0 and waits for OnOpen() to be called to activate the GameScene.

virtual TurtleBrains::Game::GameScene::~GameScene ( void  )
pure virtual

If the active GameScene is the scene being destructed the active scene will be changed to a blank scene, otherwise does nothing as the object is destructed.

Member Function Documentation

static void TurtleBrains::Game::GameScene::ChangeToScene ( GameScene gameScene)
static

Changes the active scene to the gameScene provided, immediately at the end of the current frame without any transition or effects. The current active scene, if one exists, will be closed and OnClose() will be invoked before the new gameScene is opened with OnOpen() and set as the active scene.

Parameters
gameSceneThe new scene that will be updated and displayed as the active scene. The scene must remain in scope for the entire duration while it is active. TODO: TurtleBrains: Documentation: Add a sample about creating a SceneManager and provide a template.
virtual void TurtleBrains::Game::GameScene::OnClose ( void  )
protectedvirtual

This will be called when the scene has ended and is no longer active in any manner, all resources should be cleaned up until the scene is opened again.

virtual void TurtleBrains::Game::GameScene::OnOpen ( void  )
protectedvirtual

This will be called just before the scene is actually activated so that any resources can be created or acquired for the scene to display correctly. This OnOpen() should be called to reset the accumulated simulation time just in case there had been some time remaining from a previous activation.

virtual void TurtleBrains::Game::GameScene::OnRender ( void  ) const
protectedvirtual

This will be called once per frame every frame to display the current frame of the scene.

Reimplemented from TurtleBrains::Graphics::GraphicList.

virtual void TurtleBrains::Game::GameScene::OnRuntimeReload ( void  )
protectedvirtual

This will be called IF runtime reloading is enabled and the amount time has passed

virtual void TurtleBrains::Game::GameScene::OnSimulate ( void  )
protectedvirtual

Called zero to N times per frame as simulated time accumulates. This is where game logic should live as OnSimulate() is called at a fixed rate. By default will be called at 100hz, 100 times per second with a fixed time step of 10ms or 0.01f seconds. This rate can be changed with the SetSimulateStepsPerSecond() function.

Reimplemented from TurtleBrains::Game::EntityManager.

virtual void TurtleBrains::Game::GameScene::OnUpdate ( const float  deltaTime)
protectedvirtual

Called once per frame every frame to check for any Input events or update things that are dependent on the frame / wall timer. Game logic does not generally belong in the Update function as OnSimulate() is the fixed time step for more deterministic gameplay.

Parameters
deltaTimeThe number of seconds that has passed on the wall clock since the last frame called OnUpdate(). This value will be capped, so if the frame-rate is really bad deltaTime could be lower than the actual wall-time.

Reimplemented from TurtleBrains::Game::EntityManager.

static void TurtleBrains::Game::GameScene::PerformFrame ( const float  deltaTime)
static

If there has been a scene change this will actually call the OnClose() of the current scene and OnOpen() of the pending new scene. It will then continue to perform a single frame for the scene by first calling OnSimulate() zero to N times, then calling OnUpdate and OnRender() exactly once for the active scene.

Parameters
deltaTimeThe amount of time since the last call to PerformFrame(), should already be capped if frame-rate is too low and deltaTime gets too large.
static void TurtleBrains::Game::GameScene::PerformFrame ( GameScene gameScene,
const float  deltaTime 
)
static

Perform a single frame for the provided gameScene by first calling OnSimulate() zero to N times, then calling OnUpdate and OnRender() exactly once for the provided scene.

Parameters
gameSceneThe gameScene to simulate, update and render for a single frame.
deltaTimeThe amount of time since the last call to PerformFrame(), should already be capped if frame-rate is too low and deltaTime gets too large.