Skip to content

Latest commit

 

History

History
28 lines (17 loc) · 1.23 KB

misc.md

File metadata and controls

28 lines (17 loc) · 1.23 KB

Chapter 2: Jumping into Cocos2d-x

What is the Director?

Cocos2d-x uses a shared singleton object called Director. The Director takes care of initializing OpenGL, Scene transitions, converting coordinates from UIKit to OpenGL and vice versa.

How to work with the Director?

Every Cocos2d-x application has a Director context that is created as the application is starting. The Director is created in AppDelegate::applicationDidFinishLaunching(). As the Director is a shared singleton it may be interacted with at almost any stage in your game.

Example: Get the visible screen size cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();

Example: Replacing a Scene cocos2d::Director::getInstance()->replaceScene(newScene);

Example: Showing Frames-per-second information in lower left corner cocos2d::Director::setDisplayStats(true);

Please refer to the API documentation for a complete listing of functionality.

What caching mechanisms are provided?

SpriteFrameCache

The SpriteFrameCache is a singleton that handles the loading of the sprite frames. The first time a sprite is called if it doesn't already exist in the cache it is added.

TextureCache

The TextureCache