Public Member Functions | Static Public Member Functions | Properties

CCNodeController Class Reference

An instance of CCNodeController manages a single CCNode (typically a CCLayer) as changes occur to the device orientation (portrait, landscape, etc). More...

#import <CCNodeController.h>

List of all members.

Public Member Functions

(void) - deviceOrientationDidChange:
(void) - didChangeIsOverlayingDeviceCamera
(UIImagePickerController *) - newDeviceCameraPicker
(void) - runSceneOnNode:
(void) - willChangeIsOverlayingDeviceCamera

Static Public Member Functions

(id) + controller

Properties

CCNode
< ControlledCCNodeProtocol > * 
controlledNode
ccDeviceOrientation defaultCCDeviceOrientation
BOOL doesAutoRotate
BOOL isDeviceCameraAvailable
BOOL isOverlayingDeviceCamera
UIImagePickerController * picker

Detailed Description

The controller can also overlay both the CCNode and the underlying EAGLView on top of the view of the device camera, providing an "augmented reality" display.


Member Function Documentation

+ (id) controller

Allocates and initializes an autoreleased instance.

- (void) deviceOrientationDidChange: (NSNotification *)  notification

Called automatically when the orientation of the device (portrait, landscape, etc) has changed.

Propagates the change in orientation into the cocos2D framework.

The current UIDeviceOrientation is mapped to a corresponding ccDeviceOrientation, or to the defaultCCDeviceOrientation if there is no corresponding ccDeviceOrientation. The new ccDeviceOrientation is set in the CCDirector singleton and the CCNode is sent a deviceOrientationDidChange: message.

Subclasses may override to add further behaviour, and then call this superclass implementation to have ccocos2D made aware of the change.

- (void) didChangeIsOverlayingDeviceCamera

Called automatically just after the isOverlayingDeviceCamera property has been changed, and after the picker has been modally presented or dismissed.

The isOverlayingDeviceCamera property has the new value when this call is made. Default does nothing. Subclasses can override

- (UIImagePickerController*) newDeviceCameraPicker

If the device supports a camera, returns a newly allocated and initialized UIImagePickerController, suitable for use in overlaying the EAGLView underlying the CCNode on top of the device camera image.

Returns nil if the device does not suport a camera. It is the responsibility of the caller to manage the releasing of the returned picker.

This method is automatically called when the picker property is first accessed. It should not be called directly otherwise. Subclasses can override this method to modify the characteristics of the returned picker.

- (void) runSceneOnNode: (CCNode< ControlledCCNodeProtocol > *)  aNode

This is a convenience method designed to keep the CCNode<ControlledCCNodeProtocol> being controlled by this controller synchronized with the scene being run by the shared CCDirector.

This method changes the CCNode<ControlledCCNodeProtocol> under control to the specified node, then wraps that node in a CCScene and causes that scene to be run by the shared CCDirector by calling either replaceScene: on the shared CCDirector if it is already running a scene, or runWithScene: on the shared CCDirector if it is not already running a scene.

- (void) willChangeIsOverlayingDeviceCamera

Called automatically just before the isOverlayingDeviceCamera property is about to be changed, and before the picker has been modally presented or dismissed.

The isOverlayingDeviceCamera property still has the old value when this call is made. Default does nothing. Subclasses can override


Property Documentation

- (CCNode< ControlledCCNodeProtocol > *) controlledNode [read, write, retain]

The CCNode that is being controlled by this controller.

The application should keep this property synchronized with changes in the running scene of the shared CCDirector. The convenience method runSceneOnNode: can be used to enforce this.

- (ccDeviceOrientation) defaultCCDeviceOrientation [read, write, assign]

Within cocos2D, not all UIDeviceOrientation enumerations are mapped to ccDeviceOrientations.

When the device is in a UIDeviceOrientation that is not mapped to a ccDeviceOrientation, (typically UIDeviceOrientationFaceDown or UIDeviceOrientationFaceUp), the controller will orient the CCNode to this defaultCCDeviceOrientation. The value of this property is initially set to kCCDeviceOrientationLandscapeLeft.

- (BOOL) doesAutoRotate [read, write, assign]

Indicates whether the controller should automatically rotate the rendering of the CCNode as the device orientation changes.

The value of this property is initially set to NO.

If this property is set to YES, this controller will listen for notifications of device orientation change, and propagate those changes to the cocos2D framework and the controlled CCNode<ControlledCCNodeProtocol>'s through its deviceOrientationDidChange: method.

If this property is set to NO, the application may still change the orientation of the CCNode when needed (eg- upon user control) by manually calling the CCNode<ControlledCCNodeProtocol>'s deviceOrientationDidChange: method.

- (BOOL) isDeviceCameraAvailable [read, assign]

Indicates whether this device supports a camera.

- (BOOL) isOverlayingDeviceCamera [read, write, assign]

Controls whether the controlled CCNode is overlaying the view of the device camera.

The value of this property is initially set to NO. This property can only be set to YES if a camera is actually available on the device.

If the device supports a camera, setting this property to YES will cause the controller to immediately open a view of the device camera and overlay the CCNode view on top of the device camera view.

Setting this property to NO will cause the controller to close the device camera (if it was open) and display the CCNode without the camera background.

Converting back and forth between the device camera overlay and a normal view is not a trivial activity. The simple act of changing this property causes the following sequence of actions:

  • If the CCNode is currently running, it is sent an onExit message to cause it to stop running, clean up any active actions, and reset its touch event handling. CCNode subclasses can also override onExit to perform other activities associated with cleaning up prior to the overlay changing.
  • This controller is sent a willChangeIsOverlayingDeviceCamera message.
  • The isOverlayingDeviceCamera property of this controller is changed.
  • If the isOverlayingDeviceCamera property is being set to YES, the picker UIImagePickerController is presented modally. If the isOverlayingDeviceCamera property is being set to NO, the modal picker UIImagePickerController is dismissed.
  • This controller is sent a didChangeIsOverlayingDeviceCamera message.
  • If the CCNode was running, it is sent an onEnter message to cause it to restart, be ready for actions, and, in the case of CCLayers, re-register for touch events. CCNode subclasses can also override onEnter to perform other activities associated with adjusting their world following the overlay changing (such as hiding or showing child CCNodes based on whether or not the device camera is now overlayed.
- (UIImagePickerController *) picker [read, assign]

The UIImagePickerController instance that this controller uses to overlay the CCNode on the device camera image.

This property will always return nil if the device does not support a camera.


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