Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
AssetManager Class Reference

#include <CUAssetManager.h>

Public Member Functions

int createScene ()
 
void startScene (int scene)
 
void startAll ()
 
void stopScene (int scene)
 
void stopAll ()
 
void deleteScene (int scene)
 
void deleteAll ()
 
bool hasScene (int scene) const
 
int getCurrentIndex () const
 
void setCurrentIndex (int scene)
 
SceneManagergetCurrent () const
 
SceneManagerat (int scene) const
 
SceneManageroperator[] (int scene) const
 

Static Public Member Functions

static void init ()
 
static void shutdown ()
 
static AssetManagergetInstance ()
 

Protected Attributes

std::vector< SceneManager * > _managers
 
int _scene
 

Static Protected Attributes

static AssetManager_gManager = nullptr
 

Detailed Description

Singleton class to support asset management.

Assets should always be managed by a central loader. Cocos2D appears to have these things all over the place. This helps centralize them. This is particularly useful when implementing scene management.

In scene management, each asset is attached to a scene. This allows you to unload all of the assets for a scene without unloading all assets. It is possible for an asset to be attached to multiple scenes. In that case, the scenes will attach a reference count, and the asset will only be unloaded when all associated scenes are unloaded.

This class is a singleton, in the same way that director is. That mean you should not create new instances of this object (and the constructor is protected for that very reason). Instead, you should use the static method getInstance().

Member Function Documentation

SceneManager* AssetManager::at ( int  scene) const
inline

Returns the scene manager for the given index.

If the scene is invalid, this method will raise an exception.

Parameters
sceneThe index for the scene manager
Returns
the asset manager for the given index
int AssetManager::createScene ( )

Creates a new scene for managing assets.

The new scene will be set as the current scene.

Returns
the index for the new scene manager
void AssetManager::deleteAll ( )

Deletes all of the allocated scene managers.

This method will stop the scene managers if they are still active. It will clear the asset manager and future attempts to access the previously allocated scene managers will raise an exception.

void AssetManager::deleteScene ( int  scene)

Deletes the scene manager for the given index

This method will stop the scene manager if it is still active. Future attempts to access a scene manager for this index will raise an exception.

Parameters
sceneThe index for the scene manager
SceneManager* AssetManager::getCurrent ( ) const
inline

Returns the scene manager for the current scene.

If there is no active scene, this method will return nullptr.

Returns
the asset manager for the current scene
int AssetManager::getCurrentIndex ( ) const
inline

Returns the index for the current scene.

If there is no current scene, this method will return -1.

Returns
the index for the current scene.
static AssetManager* AssetManager::getInstance ( )
inlinestatic

Returns a reference tot he global asset manager.

Returns
a reference tot he global asset manager.
bool AssetManager::hasScene ( int  scene) const
inline

Returns True if scene corresponds to an allocated scene.

In general, this method will return false if scene was deleted. However, the scene identifier may be reused by later allocations.

Returns
True if scene corresponds to an allocated scene.
void AssetManager::init ( )
static

Initializes the global asset manager.

This should be called when the application starts

SceneManager* AssetManager::operator[] ( int  scene) const
inline

Returns the scene manager for the given index.

If the scene is invalid, this method will raise an exception.

Parameters
sceneThe index for the scene manager
Returns
the asset manager for the given index
void AssetManager::setCurrentIndex ( int  scene)
inline

Sets the index for the current scene.

If there is no current scene, this method will return -1.

Parameters
sceneThe index for the current scene.
void AssetManager::shutdown ( )
static

Stops the global asset manager.

This releases all of the allocated scene managers. It should be called when the application quits.

void AssetManager::startAll ( )

Starts all of the allocated scene managers.

void AssetManager::startScene ( int  scene)

Starts the scene manager for the given index

Parameters
sceneThe index for the scene manager
void AssetManager::stopAll ( )

Stops all of the allocated scene managers.

void AssetManager::stopScene ( int  scene)

Stops the scene manager for the given index

Parameters
sceneThe index for the scene manager

Member Data Documentation

NS_CC_BEGIN AssetManager * AssetManager::_gManager = nullptr
staticprotected

The singleton asset manager

Initialization of static reference

std::vector<SceneManager*> AssetManager::_managers
protected

The managers for each individual scene

int AssetManager::_scene
protected

The current active scene


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