CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::scene2::LoadingScene Class Reference

#include <CULoadingScene.h>

Inheritance diagram for cugl::scene2::LoadingScene:
cugl::scene2::Scene2 cugl::Scene

Public Member Functions

 LoadingScene ()
 
 ~LoadingScene ()
 
void dispose ()
 
bool init (const std::string scene, const std::string directory)
 
bool init (const std::shared_ptr< cugl::AssetManager > &manager, const std::string directory)
 
std::shared_ptr< cugl::AssetManagergetAssetManager () const
 
void start ()
 
void update (float timestep)
 
float getProgress () const
 
bool isPending () const
 
bool isComplete () const
 
- Public Member Functions inherited from cugl::scene2::Scene2
 Scene2 ()
 
 ~Scene2 ()
 
virtual void dispose () override
 
virtual bool init () override
 
virtual bool initWithHint (Size hint) override
 
virtual bool initWithHint (float width, float height) override
 
Color4 getColor ()
 
void setColor (Color4 color)
 
virtual std::string toString (bool verbose=false) const override
 
size_t getChildCount () const
 
std::shared_ptr< scene2::SceneNodegetChild (unsigned int pos)
 
const std::shared_ptr< scene2::SceneNode > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< TgetChild (unsigned int pos) const
 
std::shared_ptr< scene2::SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< TgetChildByTag (unsigned int tag) const
 
std::shared_ptr< scene2::SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< TgetChildByName (const std::string name) const
 
std::vector< std::shared_ptr< scene2::SceneNode > > getChildren ()
 
const std::vector< std::shared_ptr< scene2::SceneNode > > & getChildren () const
 
virtual void addChild (const std::shared_ptr< scene2::SceneNode > &child)
 
void addChildWithTag (const std::shared_ptr< scene2::SceneNode > &child, unsigned int tag)
 
void addChildWithName (const std::shared_ptr< scene2::SceneNode > &child, const std::string name)
 
void swapChild (const std::shared_ptr< scene2::SceneNode > &child1, const std::shared_ptr< scene2::SceneNode > &child2, bool inherit=false)
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< scene2::SceneNode > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string name)
 
virtual void removeAllChildren ()
 
std::shared_ptr< graphics::SpriteBatchgetSpriteBatch () const
 
void setSpriteBatch (const std::shared_ptr< graphics::SpriteBatch > &batch)
 
virtual void render () override
 
- Public Member Functions inherited from cugl::Scene
 Scene ()
 
 ~Scene ()
 
virtual void dispose ()
 
virtual bool init ()
 
virtual bool initWithHint (Size hint)
 
virtual bool initWithHint (float width, float height)
 
const std::string getName () const
 
void setName (const std::string name)
 
std::shared_ptr< CameragetCamera ()
 
const std::shared_ptr< CameragetCamera () const
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Size getSize () const
 
const Rect getBounds () const
 
Vec3 screenToWorldCoords (const Vec2 screenCoords) const
 
Vec2 worldToScreenCoords (const Vec3 worldCoords) const
 
bool isActive () const
 
virtual void setActive (bool value)
 
virtual void update (float timestep)
 
virtual void reset ()
 
virtual void render ()
 

Static Public Member Functions

static std::shared_ptr< LoadingScenealloc (const std::string scene, const std::string directory)
 
static std::shared_ptr< LoadingScenealloc (const std::shared_ptr< cugl::AssetManager > &manager, const std::string directory)
 
- Static Public Member Functions inherited from cugl::scene2::Scene2
static std::shared_ptr< Scene2alloc ()
 
static std::shared_ptr< Scene2allocWithHint (const Size hint)
 
static std::shared_ptr< Scene2allocWithHint (float width, float height)
 

Protected Attributes

std::shared_ptr< cugl::AssetManager_assets
 
std::string _directory
 
std::shared_ptr< cugl::scene2::SceneNode_before
 
std::shared_ptr< cugl::scene2::SceneNode_after
 
std::shared_ptr< cugl::scene2::Button_button
 
std::shared_ptr< cugl::scene2::ProgressBar_bar
 
float _progress
 
bool _completed
 
bool _started
 
- Protected Attributes inherited from cugl::scene2::Scene2
std::shared_ptr< graphics::SpriteBatch_batch
 
std::vector< std::shared_ptr< scene2::SceneNode > > _children
 
Color4 _color
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
- Protected Attributes inherited from cugl::Scene
std::shared_ptr< Camera_camera
 
std::string _name
 
Size _size
 
bool _active
 

Detailed Description

This class is a simple loading screen for asychronous asset loading.

This class will either create its own AssetManager, or it can be assigned on. In the latter case, it needs a json file defining the assets for the initial loading screen. In the former, the asset manager should come preloaded with these assets. To properly display to the screen, these assets must include a scene2::SceneNode named "load". This node must have at least four children:

- "load.before": The scene to display while loading is in progress
- "load.after": The scene to display when the loading is complete
- "load.bar": A {@link ProgressBar} for showing the loading progress
- "load.play" A play {@link Button} for the user to start the game

When the play button is pressed, this scene is deactivated, indicating to the application that it is time to switch scenes.

In addition to these assets, the loading scene will take the take of an asset directory. This is a JSON file defining the assets that should be loaded asynchronously by this loading scene. Accessing the asset manager with getAssetManager gives access to these assets.

Constructor & Destructor Documentation

◆ LoadingScene()

cugl::scene2::LoadingScene::LoadingScene ( )
inline

Creates a new loading scene with the default values.

This constructor does not allocate any objects or start the scene. This allows us to use the object without a heap pointer.

◆ ~LoadingScene()

cugl::scene2::LoadingScene::~LoadingScene ( )
inline

Deletes this scene, disposing all resources.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr< LoadingScene > cugl::scene2::LoadingScene::alloc ( const std::shared_ptr< cugl::AssetManager > &  manager,
const std::string  directory 
)
inlinestatic

Returns a newly allocated loading scene with the given asset manager and directory.

The asset manager must already contain the scene graph used by this scene. The scene must include a scene2::SceneNode named "load". This node must have at least four children:

- "load.before": The scene to display while loading is in progress
- "load.after": The scene to display when the loading is complete
- "load.bar": A {@link ProgressBar} for showing the loading progress
- "load.play" A play {@link Button} for the user to start the game

The string directory is the asset directory to be loaded asynchronously by this scene. The progress on this directory can be monitored via getProgress.

Parameters
managerA previously initialized asset manager
directoryThe asset directory to load asynchronously
Returns
a newly allocated loading scene with the given asset manager and directory.

◆ alloc() [2/2]

static std::shared_ptr< LoadingScene > cugl::scene2::LoadingScene::alloc ( const std::string  scene,
const std::string  directory 
)
inlinestatic

Returns a newly allocated loading scene with the given scene and directory.

This class will create its own AssetManager, which can be accessed via getAssetManager. This asset manager will only attach loaders for graphics::Font, graphics::Texture, scene2::SceneNode and WidgetValue.

The string scene should be a path to a JSON file that defines the scene graph for this loading scene. This file will be loaded synchronously, so it should be lightweight. The scene must include a scene2::SceneNode named "load". This node must have at least four children:

- "load.before": The scene to display while loading is in progress
- "load.after": The scene to display when the loading is complete
- "load.bar": A {@link ProgressBar} for showing the loading progress
- "load.play" A play {@link Button} for the user to start the game

The string directory is the asset directory to be loaded asynchronously by this scene. The progress on this directory can be monitored via getProgress.

Parameters
sceneA JSON file with the scene graph for this scene
directoryThe asset directory to load asynchronously
Returns
a newly allocated loading scene with the given scene and directory.

◆ dispose()

void cugl::scene2::LoadingScene::dispose ( )
virtual

Disposes all of the resources used by this sceene.

A disposed node can be safely reinitialized. The scene graph owned by this scene will be released, as well as the asset manager. They will be deleted if no other object owns them.

Reimplemented from cugl::scene2::Scene2.

◆ getAssetManager()

std::shared_ptr< cugl::AssetManager > cugl::scene2::LoadingScene::getAssetManager ( ) const
inline

Returns the asset manager for this loading scene

Returns
the asset manager for this loading scene

◆ getProgress()

float cugl::scene2::LoadingScene::getProgress ( ) const
inline

Returns the current progress of this this loading scene.

The value is in the range [0,1] where 0 means no progress and 1 means that loading has completed.

Returns
the current progress of this this loading scene.

◆ init() [1/2]

bool cugl::scene2::LoadingScene::init ( const std::shared_ptr< cugl::AssetManager > &  manager,
const std::string  directory 
)

Initializes a loading scene with the given asset manager and directory.

The asset manager must already contain the scene graph used by this scene. The scene must include a scene2::SceneNode named "load". This node must have at least four children:

- "load.before": The scene to display while loading is in progress
- "load.after": The scene to display when the loading is complete
- "load.bar": A {@link ProgressBar} for showing the loading progress
- "load.play" A play {@link Button} for the user to start the game

The string directory is the asset directory to be loaded asynchronously by this scene. The progress on this directory can be monitored via getProgress.

Parameters
managerA previously initialized asset manager
directoryThe asset directory to load asynchronously
Returns
true if the scene is initialized properly, false otherwise.

◆ init() [2/2]

bool cugl::scene2::LoadingScene::init ( const std::string  scene,
const std::string  directory 
)

Initializes a loading scene with the given scene and directory.

This class will create its own AssetManager, which can be accessed via getAssetManager. This asset manager will only attach loaders for graphics::Font, graphics::Texture, scene2::SceneNode and WidgetValue.

The string scene should be a path to a JSON file that defines the scene graph for this loading scene. This file will be loaded synchronously, so it should be lightweight. The scene must include a scene2::SceneNode named "load". This node must have at least four children:

- "load.before": The scene to display while loading is in progress
- "load.after": The scene to display when the loading is complete
- "load.bar": A {@link ProgressBar} for showing the loading progress
- "load.play" A play {@link Button} for the user to start the game

The string directory is the asset directory to be loaded asynchronously by this scene. The progress on this directory can be monitored via getProgress.

Parameters
sceneA JSON file with the scene graph for this scene
directoryThe asset directory to load asynchronously
Returns
true if the scene is initialized properly, false otherwise.

◆ isComplete()

bool cugl::scene2::LoadingScene::isComplete ( ) const
inline

Returns true if loading is complete, and the player has pressed play

Returns
true if loading is complete, and the player has pressed play

◆ isPending()

bool cugl::scene2::LoadingScene::isPending ( ) const
inline

Returns true if loading is complete, but the player has not pressed play

Returns
true if loading is complete, but the player has not pressed play

◆ start()

void cugl::scene2::LoadingScene::start ( )

Starts the loading progress for this scene

This method has no affect if loading is already in progress.

◆ update()

void cugl::scene2::LoadingScene::update ( float  timestep)
virtual

Updates the loading scene progress.

This method queries the asset manager to update the progress bar amount.

Parameters
timestepThe amount of time (in seconds) since the last frame

Reimplemented from cugl::Scene.

Member Data Documentation

◆ _after

std::shared_ptr<cugl::scene2::SceneNode> cugl::scene2::LoadingScene::_after
protected

The scene during when complete

◆ _assets

std::shared_ptr<cugl::AssetManager> cugl::scene2::LoadingScene::_assets
protected

The asset manager for loading.

◆ _bar

std::shared_ptr<cugl::scene2::ProgressBar> cugl::scene2::LoadingScene::_bar
protected

The animated progress bar

◆ _before

std::shared_ptr<cugl::scene2::SceneNode> cugl::scene2::LoadingScene::_before
protected

The scene during loading

◆ _button

std::shared_ptr<cugl::scene2::Button> cugl::scene2::LoadingScene::_button
protected

The "play" button

◆ _completed

bool cugl::scene2::LoadingScene::_completed
protected

Whether or not the player has pressed play to continue

◆ _directory

std::string cugl::scene2::LoadingScene::_directory
protected

The asset directory reference

◆ _progress

float cugl::scene2::LoadingScene::_progress
protected

The progress displayed on the screen

◆ _started

bool cugl::scene2::LoadingScene::_started
protected

Whether or not the asset loader has started loading


The documentation for this class was generated from the following file: