CCAppDelegate Class Reference

Inherits from NSObject
Conforms to CCDirectorDelegate
UIApplicationDelegate
Declared in CCAppDelegate.h

Overview

Most Cocos2d apps should override the CCAppDelegate, it serves as the app’s starting point and provides a CCNavigationController.

At the very least the startScene method should be overridden to return the first scene the app should display.

To further customize the behavior of Cocos2D, such as the screen mode of pixel format, override the setupCocos2dWithOptions: method.

Accessing Window and Navigation Controller

  window

The UIWindow containing the Cocos2D view.

@property (nonatomic, strong) UIWindow *window

Declared In

CCAppDelegate.h

  navController

The navigation controller that Cocos2D is using.

@property (atomic, readonly) CCNavigationController *navController

Discussion

Note: The CCNavigationController is a subclass of UINavigationController. It implements certain navigation controller methods mainly related to orientation and projection changes Cocos2D needs to know about. Other than that it is just a regular UINavigationController.

Declared In

CCAppDelegate.h

Cocos2d Setup

– setupCocos2dWithOptions:

This method is called from the applicaton:didFinishLaunchingWithOptions: UIApplicationDelegate method. It will configure Cocos2D with the options that you provide. You can leave out any of the options to have Cocos2D use default values. Some of the settings can be changed at runtime, for instance the debug stats.

- (void)setupCocos2dWithOptions:(NSDictionary *)config

Parameters

config

Dictionary with setup options for Cocos2D.

Discussion

Currently supported keys for the configuration dictionary are:

  • CCSetupPixelFormat: NSString with the pixel format, normally kEAGLColorFormatRGBA8 or kEAGLColorFormatRGB565. The RGB565 option is faster and recommended, unless color vibrancy is noticably impaired or you need the alpha channel.
  • CCSetupScreenMode: NSString value that accepts either CCScreenModeFlexible or CCScreenModeFixed.
  • CCSetupScreenOrientation: NSString value that accepts CCScreenOrientationLandscape, CCScreenOrientationPortrait, or CCScreenOrientationAll.
  • CCSetupAnimationInterval: NSNumber with double. Specifies the desired interval between animation frames. Supported values are 1.0/60.0 (default, 60 fps) and 1.0/30.0 (30 fps).
  • CCSetupFixedUpdateInterval: NSNumber with double. Specifies the desired interval between fixed updates. Should be smaller than CCSetupAnimationInterval. Defaults to 1.0/60.0 (60 Hz).
  • CCSetupShowDebugStats: NSNumber with bool. Specifies if the stats (FPS, frame time and draw call count) should be rendered. Defaults to NO.
  • CCSetupTabletScale2X: NSNumber with bool. If true, the iPad will be setup to act like it has a 512x384 points “logical” screen size with a “Retina” pixel resolution of 1024x768. This makes it much easier to make universal iOS games. This is the default mode for CocosBuilder projects. This value is ignored when using the fixed screen mode.

  • CCSetupDepthFormat: NSNumber with integer. Specifies the desired depth buffer format. Values are 0 (no depth buffering), GL_DEPTH24_STENCIL8_OES (8-Bit depth buffer) and GL_DEPTH_COMPONENT24_OES (24-bit depth buffer). Depth buffering is only needed in rare cases and comes at the expense of performance and additional memory usage.

  • CCSetupPreserveBackbuffer: NSNumber with bool. Specifies whether backbuffer will be preserved. Defaults to NO.
  • CCSetupMultiSampling: NSNumber with bool. Specifies whether multisampling (fullscreen anti-aliasing) is enabled. Defaults to NO.
  • CCSetupNumberOfSamples: NSNumber with integer. Specifies number of samples when multisampling is enabled. Ignored if multisampling is not enabled.

Declared In

CCAppDelegate.h