Public Member Functions | Static Public Member Functions | Properties

CCNode Class Reference

#import "CCNode.h"

Inherited by CCAtlasNode, CCLayer, CCMenuItem, CCMotionStreak, CCParallaxNode, CCParticleSystem, CCProgressTimer, CCRenderTexture, CCRibbon, CCScene, CCSprite, CCSpriteBatchNode, and CCTMXTiledMap.

Collaboration diagram for CCNode:
[legend]

List of all members.

Public Member Functions

(void) - addChild:
(void) - addChild:z:
(void) - addChild:z:tag:
(CGRect) - boundingBox
(CGRect) - boundingBoxInPixels
(void) - cleanup
(CGPoint) - convertToNodeSpace:
(CGPoint) - convertToNodeSpaceAR:
(CGPoint) - convertTouchToNodeSpace:
(CGPoint) - convertTouchToNodeSpaceAR:
(CGPoint) - convertToWorldSpace:
(CGPoint) - convertToWorldSpaceAR:
(void) - draw
(CCAction *) - getActionByTag:
(CCNode *) - getChildByTag:
(id) - init
(CGAffineTransform) - nodeToParentTransform
(CGAffineTransform) - nodeToWorldTransform
(int) - numberOfRunningActions
(void) - onEnter
(void) - onEnterTransitionDidFinish
(void) - onExit
(CGAffineTransform) - parentToNodeTransform
(void) - pauseSchedulerAndActions
(void) - removeAllChildrenWithCleanup:
(void) - removeChild:cleanup:
(void) - removeChildByTag:cleanup:
(void) - removeFromParentAndCleanup:
(void) - reorderChild:z:
(void) - resumeSchedulerAndActions
(CCAction *) - runAction:
(void) - schedule:
(void) - schedule:interval:
(void) - scheduleUpdate
(void) - scheduleUpdateWithPriority:
(void) - stopAction:
(void) - stopActionByTag:
(void) - stopAllActions
(void) - transform
(void) - transformAncestors
(void) - unschedule:
(void) - unscheduleAllSelectors
(void) - visit
(CGAffineTransform) - worldToNodeTransform

Static Public Member Functions

(id) + node

Properties

CGPoint anchorPoint
CGPoint anchorPointInPixels
CCCameracamera
CCArraychildren
CGSize contentSize
CGSize contentSizeInPixels
CCGridBasegrid
BOOL isRelativeAnchorPoint
BOOL isRunning
CCNodeparent
CGPoint position
CGPoint positionInPixels
float rotation
float scale
float scaleX
float scaleY
NSInteger tag
void * userData
float vertexZ
BOOL visible
NSInteger zOrder

Detailed Description

CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode. The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.

The main features of a CCNode are:

Some CCNode nodes provide extra functionality for them or their children.

Subclassing a CCNode usually means (one/all) of:

Features of CCNode:

Default values:

Limitations:

Order in transformations with grid disabled

  1. The node will be translated (position)
  2. The node will be rotated (rotation)
  3. The node will be scaled (scale)
  4. The node will be moved according to the camera values (camera)

Order in transformations with grid enabled

  1. The node will be translated (position)
  2. The node will be rotated (rotation)
  3. The node will be scaled (scale)
  4. The grid will capture the screen
  5. The node will be moved according to the camera values (camera)
  6. The grid will render the captured screen

Camera:


Member Function Documentation

- (void) addChild: (CCNode *)  node  

Adds a child to the container with z-order as 0. If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.

Since:
v0.7.1
- (void) addChild: (CCNode *)  node
z: (int)  z 

Adds a child to the container with a z-order. If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.

Since:
v0.7.1
- (void) addChild: (CCNode *)  node
z: (int)  z
tag: (int)  tag 

Adds a child to the container with z order and tag. If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.

Since:
v0.7.1
- (CGRect) boundingBox  

returns a "local" axis aligned bounding box of the node in points. The returned box is relative only to its parent. The returned box is in Points.

Since:
v0.8.2
- (CGRect) boundingBoxInPixels  

returns a "local" axis aligned bounding box of the node in pixels. The returned box is relative only to its parent. The returned box is in Points.

Since:
v0.99.5
- (void) cleanup  

Stops all running actions and schedulers. IMPORTANT: if you override this method in your class you MUST call [super cleanup] otherwise actions/schedulers may not be deallocated, causing the whole node to be leaked!

Since:
v0.8
- (CGPoint) convertToNodeSpace: (CGPoint)  worldPoint  

Converts a Point to node (local) space coordinates. The result is in Points.

Since:
v0.7.1
- (CGPoint) convertToNodeSpaceAR: (CGPoint)  worldPoint  

Converts a Point to node (local) space coordinates. The result is in Points. treating the returned/received node point as anchor relative.

Since:
v0.7.1
- (CGPoint) convertTouchToNodeSpace: (UITouch *)  touch  

Converts a UITouch to node (local) space coordinates. The result is in Points.

Since:
v0.7.1
- (CGPoint) convertTouchToNodeSpaceAR: (UITouch *)  touch  

Converts a UITouch to node (local) space coordinates. The result is in Points. This method is AR (Anchor Relative)..

Since:
v0.7.1
- (CGPoint) convertToWorldSpace: (CGPoint)  nodePoint  

Converts a Point to world space coordinates. The result is in Points.

Since:
v0.7.1
- (CGPoint) convertToWorldSpaceAR: (CGPoint)  nodePoint  

Converts a local Point to world space coordinates.The result is in Points. treating the returned/received node point as anchor relative.

Since:
v0.7.1
- (void) draw  

Override this method to draw your own node. The following GL states will be enabled by default:

  • glEnableClientState(GL_VERTEX_ARRAY);
  • glEnableClientState(GL_COLOR_ARRAY);
  • glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  • glEnable(GL_TEXTURE_2D);

AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE

But if you enable any other GL state, you should disable it after drawing your node.

IMPORTANT: you should always call [super draw] if you override this method out of "good OOP manners", even if it normally doesn't draw itself (eg. CCNode).

- (CCAction*) getActionByTag: (int)  tag  

Gets an action from the running action list given its tag

Since:
v0.7.1
Returns:
the Action the with the given tag
- (CCNode*) getChildByTag: (int)  tag  

Gets a child from the container given its tag

Returns:
returns a CCNode object
Since:
v0.7.1
- (id) init  

Default initializer.

+ (id) node  

Default autorelease initializer. Allocates and initializes a node and sends the autorelease message to it.

- (CGAffineTransform) nodeToParentTransform  

Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates. The matrix is in Pixels.

Since:
v0.7.1
- (CGAffineTransform) nodeToWorldTransform  

Retrusn the world affine transform matrix. The matrix is in Pixels.

Since:
v0.7.1
- (int) numberOfRunningActions  

Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays). Composable actions are counted as 1 action. Example: If you are running 1 Sequence of 7 actions, it will return 1. If you are running 7 Sequences of 2 actions, it will return 7.

- (void) onEnter  

Called every time the CCNode becomes active in the node hierarchy, for example by adding it as child or when transitioning to a new scene. If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts. IMPORTANT: Within this method you must not modify the [[self parent] children] array. IMPORTANT: If you override this method in your class you MUST call [super onEnter] to make sure the node is fully initialized!

- (void) onEnterTransitionDidFinish  

Same as onEnter, except it is called when the transition has finished. If there is no transition it will be called right after onEnter. IMPORTANT: Within this method you must not modify the [[self parent] children] array. IMPORTANT: if you override this method in your class you MUST call [super onEnter] to make sure the node is fully initialized!

Since:
v0.8
- (void) onExit  

Called every time the CCNode becomes inactive in the node hierarchy, for example by removing it from its parent or when transitioning to a different scene. If the CCNode leaves the 'stage' with a transition, this callback is called when the transition finishes. IMPORTANT: Within this method you must not modify the [[self parent] children] array. IMPORTANT: if you override this method in your class you MUST call [super onEnter] to make sure the node is fully initialized!

- (CGAffineTransform) parentToNodeTransform  

Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates. The matrix is in Pixels.

Since:
v0.7.1
- (void) pauseSchedulerAndActions  

pauses all scheduled selectors and actions. Called internally by onExit

- (void) removeAllChildrenWithCleanup: (BOOL)  cleanup  

Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.

Since:
v0.7.1
- (void) removeChild: (CCNode *)  node
cleanup: (BOOL)  cleanup 

Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.

Since:
v0.7.1
- (void) removeChildByTag: (int)  tag
cleanup: (BOOL)  cleanup 

Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter

Since:
v0.7.1
- (void) removeFromParentAndCleanup: (BOOL)  cleanup  

Remove itself from its parent node. If cleanup is YES, then also remove all actions and callbacks. If the node orphan, then nothing happens.

Since:
v0.99.3
- (void) reorderChild: (CCNode *)  child
z: (int)  zOrder 

Reorders a child according to a new z value. The child MUST be already added. Keep in mind that this method removes and inserts the child to the children array which can be a costly operation if there are many (hundreds) of children. If you need to reorder Z often consider switching to 2D Projection with Depth Buffer and using the vertexZ property to change the z order of nodes.

- (void) resumeSchedulerAndActions  

resumes all scheduled selectors and actions. Called internally by onEnter

- (CCAction*) runAction: (CCAction *)  action  

Executes an action, and returns the action that is executed. The node becomes the action's target.

Warning:
Starting from v0.8 actions don't retain their target anymore.
Since:
v0.7.1
Returns:
An Action pointer
- (void) schedule: (SEL)  s  

schedules a selector. The scheduled selector will be called every frame. The first call will be in the frame after the selector was scheduled, so you can use this method to delay execution of a method by one frame.

- (void) schedule: (SEL)  s
interval: (ccTime seconds 

schedules a custom selector with an interval time in seconds. If time is 0 it will be ticked every frame. If time is 0, it is recommended to use 'scheduleUpdate' instead.

If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.

- (void) scheduleUpdate  

check whether a selector is scheduled. schedules the "update" method. It will use the order number 0. This method will be called every frame. Scheduled methods with a lower order value will be called before the ones that have a higher order value. Only one "udpate" method could be scheduled per node.

Since:
v0.99.3
- (void) scheduleUpdateWithPriority: (int)  priority  

schedules the "update" selector with a custom priority. This selector will be called every frame. Scheduled selectors with a lower priority will be called before the ones that have a higher value. Only one "udpate" selector could be scheduled per node (You can't have 2 'update' selectors).

Since:
v0.99.3
- (void) stopAction: (CCAction *)  action  

Removes an action from the running action list

- (void) stopActionByTag: (int)  tag  

Removes an action from the running action list given its tag

Since:
v0.7.1
- (void) stopAllActions  

Removes all actions from the running action list

- (void) transform  

performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes.

- (void) transformAncestors  

performs OpenGL view-matrix transformation of it's ancestors. Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO) it's necessary to transform the ancestors again.

Since:
v0.7.2
- (void) unschedule: (SEL)  s  

unschedules a custom selector. Use [self unschedule:_cmd] within a scheduled selector to unschedule that specific selector without having to refer to it by name.

- (void) unscheduleAllSelectors  

unschedule all scheduled selectors: custom selectors, and the 'update' selector. Actions are not affected by this method.

Since:
v0.99.3
- (void) visit  

Recursive method that visit its children and draw them.

- (CGAffineTransform) worldToNodeTransform  

Returns the inverse world affine transform matrix. The matrix is in Pixels.

Since:
v0.7.1

Property Documentation

- (CGPoint) anchorPoint [read, write, assign]

anchorPoint is the point around which all transformations and positioning manipulations take place. It's like a pin in the node where it is "attached" to its parent. The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner. But you can use values higher than (1,1) and lower than (0,0) too. The default anchorPoint for CCNode is (0, 0). CCSprite and other subclasses have a different default anchorPoint, usually (0.5f, 0.5f).

Since:
v0.8
- (CGPoint) anchorPointInPixels [read, assign]

The anchorPoint in absolute pixels. Since v0.8 you can only read it. If you wish to modify it, use anchorPoint instead

- (CCCamera*) camera [read, assign]

A CCCamera object that lets you move the node using a gluLookAt. Note: an often made misconception is that you have to work with the camera in order to implement scrolling worlds. Instead, prefer to move the layer where the world objects are added to instead.

- (CCArray*) children [read, assign]

Array of children. Any class derived from CCNode can be added as child.

- (CGSize) contentSize [read, write, assign]

The untransformed size of the node in Points The contentSize remains the same no matter the node is scaled or rotated. All nodes has a size. Layer and Scene has the same size of the screen.

Since:
v0.8
- (CGSize) contentSizeInPixels [read, write, assign]

The untransformed size of the node in Pixels The contentSize remains the same no matter the node is scaled or rotated. All nodes has a size. Layer and Scene has the same size of the screen.

Since:
v0.8
- (CCGridBase*) grid [read, write, retain]

A CCGrid object that is used when applying effects. You don't normally use this yourself.

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

If YES the transformtions will be relative to it's anchor point. Sprites, Labels and any other sizeble object use it have it enabled by default. Scenes, Layers and other "whole screen" object don't use it, have it disabled by default.

- (BOOL) isRunning [read, assign]

whether or not the node is running

- (CCNode*) parent [read, write, assign]

A weak reference to the parent

- (CGPoint) position [read, write, assign]

Position (x,y) of the node in points. (0, 0) is the left-bottom corner in all device orientations contrary to what you may be used to from other game engines or UIKit. On standard iPhone/iPod and Retina iPhone/iPod the upper right corner is 320x480 in portrait and 480x320 in landscape orientations. On the iPad it's 1024x768 respectively 768x1024. It is highly recommend to design your game to use points (position) and refrain from using pixels (positionInPixels) unless you have a very good reason to do so.

- (CGPoint) positionInPixels [read, write, assign]

Position (x,y) of the node in pixels. (0, 0) is the left-bottom corner, on standard iPhone/iPod the upper right corner is 320x480 (480x320 in landscape) but on Retina devices it's 640x960 (960x640 in landscape).

- (float) rotation [read, write, assign]

The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node clockwise.

- (float) scale [read, write, assign]

The scale factor of the node. 1.0 is the default scale factor. It modifies the X and Y scale at the same time. Note that scaling is done by the CPU. Scaling up (scale > 1) will also increase the fillrate and scaling in any direction will decrease image quality. It is strongly recommended to design your game's graphics in a way that they can be used with scale of 1.0 at all times and to use scaling only in rare and justified circumstances with small sprites.

- (float) scaleX [read, write, assign]

The scale factor of the node. 1.0 is the default scale factor. It only modifies the X scale factor. Please also see the notes for the scale property.

- (float) scaleY [read, write, assign]

The scale factor of the node. 1.0 is the default scale factor. It only modifies the Y scale factor. Please also see the notes for the scale property.

- (NSInteger) tag [read, write, assign]

A tag used to identify the node easily. Prefer to use an enum to name each tag value.

- (void*) userData [read, write, assign]

A custom user data pointer. Note that this pointer is NOT retained.

- (float) vertexZ [read, write, assign]

The real openGL Z vertex. Differences between openGL Z vertex and cocos2d Z order:

  • vertexZ modifies the Z order of the vertices, and not the Z order in the relation between parent-children
  • vertexZ requires to set 2D projection in CCDirector and a Depth Buffer in EAGLView or MacGLView
  • if using vertexZ the regular zOrder of nodes may no longer work as expected, it's best to completely use only one way or the other for each scene.
    Since:
    v0.8
- (BOOL) visible [read, write, assign]

Whether of not the node is visible. Default is YES. If NO, the node is not drawn which saves performance. This is especially important to keep in mind when you fade out (change opacity to 0) of nodes that support opacity. With opacity 0 but visible = YES the node would technically still be drawn and strain the fillrate/GPU.

- (NSInteger) zOrder [read, assign]

The z order of the node relative to it's "brothers": children of the same parent


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