A Scene is the place where GameObject entities exists. NOTE: Users will use the SceneManager to access and set scene entities.
More...
A Scene is the place where GameObject entities exists. NOTE: Users will use the SceneManager to access and set scene entities.
Scenes handle many of services and callbacks that GameObject entities have such as updating, drawing, inputs, and collisions The Scene entities are managed by SceneManager. The SceneManager allows user access to the current scene. As well as setting the next scene. When deriving from Scene, there are two methods the users musth implement: Scene::initialize and Scene::sceneEnd.
Scene::initialize is where the user instantiates GameObject entities. Also Scene::setCollisionPair() and Scene::setCollisionSelf() that are to be tested within the scene. Refer to Collisions for more information about collisions. As well as setting the terrain (by calling Scene::setTerrain()) the user wants to use in the scene (optional).
Scene::sceneEnd is where the user deletes any GameObject entities created and where entities created by factories should be recalled here.
Here is an example of how a user defined scene would be set up. NOTE: Tanks create bullets with a factory so the factory must recall all bullets in Scene::sceneEnd().
LevelOneScene::initialize()
{
setCollisionSelf<Tank>();
setCollisionPair<Tank, Bullet>();
setCollisionSelf<Bullet>();
setCollisionPair<Bullet, WindMill>();
setCollisionPair<Bullet, Warehouse>();
setCollisionPair<Bullet, Tree>();
setCollisionTerrain<Tank>();
setCollisionTerrain<Bullet>();
Tank* pPlayerTank = new Tank();
Tank* pEnemyTank = new Tank();
WindMill* pWindMill_1 = new WindMill();
WindMill* pWindMill_2 = new WindMill();
}
LevelOneScene::sceneEnd()
{
delete pPlayerTank
delete pEnemyTank;
delete pWindMill_1;
delete pWindMill_2;
BulletFactory::RecallBullets();
}
void setTerrain(const std::string &terrainObjectName)
Sets the terrain to be used in the scene.
Definition: Scene.cpp:8
For switching to another scene we call on SceneManager::SetNextScene() and pass in the scene we want to switch to. Here is an example of how a user defined GameObject SceneChanger could be used to switch to another scene NOTE: You must include SceneManager.h header file to access SceneManager.
#include "SceneManager.h"
SceneChanger::SceneChanger(
Scene* pNextScene)
{
_pNextScene = pNextScene;
}
SceneChanger::keyPressed(AZUL_KEY key)
{
if(key == AZUL_KEY::SPACE)
{
this->switchScene();
}
}
SceneChanger::switchScene()
{
}
A scene. The place where user defined game objects are created and controlled. Scene handles game obj...
Definition: Scene.h:33
void submitKeyRegistration(AZUL_KEY key, InputEvent eventType)
Submit key registration to current scene.
Definition: Inputable.cpp:29
static void SetNextScene(Scene *pScene)
Sets the next scene to change to.
Definition: SceneManager.h:118
◆ getCurrent2DCamera()
Camera * Scene::getCurrent2DCamera |
( |
| ) |
const |
Gets the current 2D camera.
- Returns
- the current 2D camera.
◆ getCurrentCamera()
Camera * Scene::getCurrentCamera |
( |
| ) |
const |
Gets the current camera.
- Returns
- current camera.
◆ GetCurrentScene()
static Scene* SceneManager::GetCurrentScene |
( |
| ) |
|
|
inlinestatic |
Gets the current scene.
- Returns
- the current scene.
◆ getDefault2DCamera()
Camera * Scene::getDefault2DCamera |
( |
| ) |
const |
Gets default 2D camera.
- Returns
- the default 2D camera.
◆ getDefaultCamera()
Camera * Scene::getDefaultCamera |
( |
| ) |
const |
Gets the default camera.
- Returns
- the default camera.
◆ initialize()
virtual void Scene::initialize |
( |
| ) |
|
|
privatepure virtual |
Initializes this scene.
Implemented in NullScene.
◆ sceneEnd()
virtual void Scene::sceneEnd |
( |
| ) |
|
|
privatepure virtual |
◆ setCollisionPair()
template<class UserClass1 , class UserClass2 >
void Scene::setCollisionPair |
( |
| ) |
|
|
inlineprotected |
Sets collision pair between two user defined classes.
- Template Parameters
-
UserClass1 | Type of the user class 1. |
UserClass2 | Type of the user class 2. |
◆ setCollisionSelf()
template<class UserClass >
void Scene::setCollisionSelf |
( |
| ) |
|
|
inlineprotected |
Sets collision within a single user defined class.
- Template Parameters
-
UserClass | Type of the user class. |
◆ setCollisionTerrain()
template<class UserClass >
void Scene::setCollisionTerrain |
( |
| ) |
|
|
inlineprotected |
Sets collision with the terrain.
- Template Parameters
-
UserClass | Type of the user class. |
◆ setCurrent2DCamera()
void Scene::setCurrent2DCamera |
( |
Camera * |
p2DCamera | ) |
|
Sets current 2D camera.
- Parameters
-
p2DCamera | pointer to a 2D Camera. |
◆ setCurrentCamera()
void Scene::setCurrentCamera |
( |
Camera * |
pCamera | ) |
|
Sets current camera./
- Parameters
-
pCamera | pointer to a camera |
◆ setDefault2DCameraAsCurrentCamera()
void Scene::setDefault2DCameraAsCurrentCamera |
( |
| ) |
|
Sets default 2D camera as current camera 2D.
◆ setDefaultCameraAsCurrentCamera()
void Scene::setDefaultCameraAsCurrentCamera |
( |
| ) |
|
Sets default camera as current camera./
◆ SetNextScene()
static void SceneManager::SetNextScene |
( |
Scene * |
pScene | ) |
|
|
inlinestatic |
Sets the next scene to change to.
- Parameters
-
pScene | pointer to the next scene. |
◆ SetStartScene()
static void SceneManager::SetStartScene |
( |
Scene * |
pScene | ) |
|
|
inlinestatic |
Sets a start scene to begin with.
- Parameters
-
pScene | pointer to the start scene. |
◆ setTerrain()
void Scene::setTerrain |
( |
const std::string & |
terrainObjectName | ) |
|
|
protected |
Sets the terrain to be used in the scene.
- Parameters
-
terrainObjectName | the name of the terrain object. |