![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A scene in the game. More...
#include <gf/Scene.h>
Public Member Functions | |
Scene (Vector2i initialSize) | |
Constructor. More... | |
virtual | ~Scene () |
Destructor. More... | |
Game loop | |
void | processEvent (Event &event) |
Process an event. More... | |
void | handleActions (Window &window) |
Handle actions. More... | |
void | update (Time time) |
Update the scene. More... | |
void | render (RenderTarget &target, const RenderStates &states=RenderStates()) |
Render the scene. More... | |
void | setFramebufferSize (gf::Vector2i size) |
Update the framebuffer size. More... | |
void | setClearColor (gf::Color4f color) |
Set the new clear color. More... | |
gf::Color4f | getClearColor () const |
Get the current clear color. More... | |
Scene properties | |
void | setActive (bool active=true) |
Change the active state of the scene. More... | |
bool | isActive () const |
Check if the scene is active. More... | |
void | pause () |
Pause the scene. More... | |
void | resume () |
Resume the scene. More... | |
bool | isPaused () const |
Check if the scene is paused. More... | |
void | hide () |
Hide the scene. More... | |
void | show () |
Show the scene. More... | |
bool | isHidden () const |
Check if the scene is hidden. More... | |
Scene content | |
void | addView (AdaptativeView &view) |
Add a view to the scene. More... | |
void | addAction (Action &action) |
Add an action to the scene. More... | |
void | addModel (Model &model) |
Add a model to the scene. More... | |
void | addWorldEntity (Entity &entity) |
Add a world entity to the scene. More... | |
Entity * | removeWorldEntity (Entity *entity) |
Remove a world entity from the scene. More... | |
void | addHudEntity (Entity &entity) |
Add a HUD entity to the scene. More... | |
Entity * | removeHudEntity (Entity *entity) |
Remove a HUD entity from the scene. More... | |
World view management | |
void | setWorldViewCenter (Vector2f center) |
Set the center of the world view. More... | |
void | setWorldViewSize (Vector2f size) |
Set the size of the world view. More... | |
Protected Member Functions | |
void | renderWorldEntities (RenderTarget &target, const RenderStates &states) |
Render the world entities. More... | |
void | renderHudEntities (RenderTarget &target, const RenderStates &states) |
Render the HUD entities. More... | |
View & | getWorldView () |
Get the world view. More... | |
View & | getHudView () |
Get the HUD view. More... | |
EntityContainer & | getWorldEntities () |
Get the world entities. More... | |
EntityContainer & | getHudEntities () |
Get the HUD entities. More... | |
virtual bool | doEarlyProcessEvent (Event &event) |
Customization point for processEvent() More... | |
virtual void | doProcessEvent (Event &event) |
Customization point for processEvent() More... | |
virtual void | doHandleActions (Window &window) |
Customization point for handleActions() More... | |
virtual void | doUpdate (Time time) |
Customization point for update() More... | |
virtual void | doRender (RenderTarget &target, const RenderStates &states) |
Customization point for render() More... | |
virtual void | doPause () |
Customization point for pause() More... | |
virtual void | doResume () |
Customization point for resume() More... | |
virtual void | doHide () |
Customization point for hide() More... | |
virtual void | doShow () |
Customization point for show() More... | |
virtual void | onActivityChange (bool active) |
Callback when the scene becomes active or inactive. More... | |
A scene in the game.
A scene is a set of entities that are handled together in the game. A scene is associated with a set of user actions. A scene is responsible for handling the steps of a game: handling the input (and the actions), updating the entities, rendering the entities.
A scene can be associated to a scene manager, with other scenes. A scene is active when it is the top scene on the stack of scenes. The scene manager is responsible for activating and desactivating the scenes.
A scene can be either paused or resumed. A paused scene is not updated. In other words, the update step is discarded. It is the user's responsability to pause or resume a scene. An active scene is always resumed when becoming active.
A scene can be either hidden or shown. A hidden scene is not rendererd. In other words, the render step is discarded. It is the user's responsability to hide or show a scene. An active scene is always shown when becoming active.
gf::Scene::Scene | ( | Vector2i | initialSize | ) |
Constructor.
At construction, a scene is paused, hidden and inactive.
initialSize | The initial screen size |
|
virtual |
Destructor.
|
inline |
Add an action to the scene.
action | The action |
|
inline |
Add a HUD entity to the scene.
entity | The entity |
|
inline |
Add a model to the scene.
model | The model |
|
inline |
Add a view to the scene.
view | A custom view |
|
inline |
Add a world entity to the scene.
entity | The entity |
|
protectedvirtual |
Customization point for processEvent()
|
protectedvirtual |
Customization point for handleActions()
|
protectedvirtual |
Customization point for hide()
|
protectedvirtual |
Customization point for pause()
|
protectedvirtual |
Customization point for processEvent()
|
protectedvirtual |
Customization point for render()
|
protectedvirtual |
Customization point for resume()
|
protectedvirtual |
Customization point for show()
|
inline |
|
inlineprotected |
Get the HUD entities.
|
inlineprotected |
Get the HUD view.
|
inlineprotected |
Get the world entities.
|
inlineprotected |
Get the world view.
void gf::Scene::handleActions | ( | Window & | window | ) |
Handle actions.
This function must be customized with doHandleActions() in order to handle the actions that have been updated with the event processing.
At the end of this function, all the actions are resetted.
window | The current window |
void gf::Scene::hide | ( | ) |
bool gf::Scene::isActive | ( | ) | const |
Check if the scene is active.
bool gf::Scene::isHidden | ( | ) | const |
bool gf::Scene::isPaused | ( | ) | const |
|
protectedvirtual |
Callback when the scene becomes active or inactive.
active | The new status of the scene |
void gf::Scene::pause | ( | ) |
void gf::Scene::processEvent | ( | Event & | event | ) |
Process an event.
All the registered views and actions are updated with the event.
This function can be customized with doProcessEvent() that is called after all other event processing.
event | The event |
Remove a HUD entity from the scene.
entity | The entity |
Remove a world entity from the scene.
entity | The entity |
void gf::Scene::render | ( | RenderTarget & | target, |
const RenderStates & | states = RenderStates() |
||
) |
Render the scene.
This function render all the entities of the scene, if the scene is not hidden. It can be customized with doRender().
By default, it first renders the world entities (with a gf::ExtendView) through a call to renderWorldEntities() and then it renders the HUD entities (with a gf::ScreenView) through a call to renderHudEntities().
target | The target to render the scene |
states | The render states to use for drawing |
|
protected |
Render the HUD entities.
|
protected |
Render the world entities.
void gf::Scene::resume | ( | ) |
Resume the scene.
void gf::Scene::setActive | ( | bool | active = true | ) |
Change the active state of the scene.
active | The new state of the scene |
|
inline |
void gf::Scene::setFramebufferSize | ( | gf::Vector2i | size | ) |
Update the framebuffer size.
This function is called to update the views in the scene.
size | The new size of the framebuffer |
void gf::Scene::setWorldViewCenter | ( | Vector2f | center | ) |
Set the center of the world view.
center | The new center |
void gf::Scene::setWorldViewSize | ( | Vector2f | size | ) |
Set the size of the world view.
size | The new size |
void gf::Scene::show | ( | ) |
Show the scene.
void gf::Scene::update | ( | Time | time | ) |
Update the scene.
This function updates all the models and entities of the scene, if the scene is not paused. It can be customized with doUpdate() that is called after all other updates.
time | The time since the last frame |