cocos2d for iPhone  2.0.0
2D game engine for iOS and OS X
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
Public Member Functions | Static Public Member Functions | Properties
CCNode Class Reference

#import <CCNode.h>

Inheritance diagram for CCNode:
Inheritance graph
[legend]
Collaboration diagram for CCNode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Static Public Member Functions

(id) + node

Properties

NSInteger zOrder
float vertexZ
float skewX
float skewY
float rotation
float scale
float scaleX
float scaleY
CGPoint position
CCCameracamera
CCArray * children
CCGridBasegrid
BOOL visible
CGPoint anchorPoint
CGPoint anchorPointInPoints
CGSize contentSize
BOOL isRunning
CCNodeparent
BOOL isRelativeAnchorPoint
NSInteger tag
void * userData
id userObject
CCGLProgramshaderProgram
NSUInteger orderOfArrival
ccGLServerState glServerState
CCActionManageractionManager
CCScheduler * scheduler

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 skewed (skewX, skewY)
  4. The node will be scaled (scale, scaleX, scaleY)
  5. 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 skewed (skewX, skewY)
  4. The node will be scaled (scale, scaleX, scaleY)
  5. The grid will capture the screen
  6. The node will be moved according to the camera values (camera)
  7. The grid will render the captured screen

Camera:

Definition at line 103 of file CCNode.h.


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: (NSInteger)  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: (NSInteger)  z
tag: (NSInteger)  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

Implemented in CCTMXLayer.

- (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
- (void) cleanup

Event that is called when the running node is no longer running (eg: its CCScene is being removed from the "stage" ). On cleanup you should break any possible circular references. CCNode's cleanup removes any possible scheduled timer and/or any possible action. If you override cleanup, you shall call [super cleanup]

Since:
v0.8

Implemented in CCMenuItem.

- (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) 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. You should use cocos2d's GL API to enable/disable the GL state / shaders. For further info, please see ccGLstate.h. You shall NOT call [super draw];

- (CCAction*) getActionByTag: (NSInteger)  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: (NSInteger)  tag

Gets a child from the container given its tag

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

initializes the node

+ (id) node

allocates and initializes a node. The node will be created as "autorelease".

- (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
- (NSUInteger) 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

Event that is called every time the CCNode enters the 'stage'. If the CCNode enters the 'stage' with a transition, this event is called when the transition starts. During onEnter you can't access a sibling node. If you override onEnter, you shall call [super onEnter].

Event that is called when the CCNode enters in the 'stage'. If the CCNode enters the 'stage' with a transition, this event is called when the transition finishes. If you override onEnterTransitionDidFinish, you shall call [super onEnterTransitionDidFinish].

Since:
v0.8
- (void) onExit

Event that is called every time the CCNode leaves the 'stage'. If the CCNode leaves the 'stage' with a transition, this event is called when the transition finishes. During onExit you can't access a sibling node. If you override onExit, you shall call [super onExit].

callback that is called every time the CCNode leaves the 'stage'. If the CCNode leaves the 'stage' with a transition, this callback is called when the transition starts.

- (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

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: (NSInteger)  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: (NSInteger)  zOrder 

Reorders a child according to a new z value. The child MUST be already added.

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 ticked every 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) schedule: (SEL)  selector
interval: (ccTime interval
repeat: (uint)  repeat
delay: (ccTime delay 

repeat will execute the action repeat + 1 times, for a continues action use kCCRepeatForever delay is the amount of time the action will wait before execution

- (void) scheduleOnce: (SEL)  selector
delay: (ccTime delay 

Schedules a selector that runs only once, with a delay of 0 or larger

- (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: (NSInteger)  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) sortAllChildren

performance improvement, Sort the children array once before drawing, instead of every time when a child is added or reordered don't call this manually unless a child added needs to be removed in the same frame

- (void) stopAction: (CCAction *)  action

Removes an action from the running action list

- (void) stopActionByTag: (NSInteger)  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.

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

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

unschedules a custom selector.

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

- (CCActionManager*) actionManager [read, write, retain]

CCActionManager used by all the actions. IMPORTANT: If you set a new CCActionManager, then previously created actions are going to be removed.

Since:
v2.0

Definition at line 280 of file CCNode.h.

- (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 is (0,0). It starts in the bottom-left corner. CCSprite and other subclasses have a different default anchorPoint.

Since:
v0.8

Definition at line 234 of file CCNode.h.

- (CGPoint) anchorPointInPoints [read, assign]

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

Definition at line 238 of file CCNode.h.

- (CCCamera*) camera [read, assign]

A CCCamera object that lets you move the node using a gluLookAt

Definition at line 220 of file CCNode.h.

- (CCArray*) children [read, assign]

Array of children

Definition at line 222 of file CCNode.h.

- (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

Definition at line 245 of file CCNode.h.

- (ccGLServerState) glServerState [read, write, assign]

GL server side state

Since:
v2.0

Definition at line 274 of file CCNode.h.

- (CCGridBase*) grid [read, write, retain]

A CCGrid object that is used when applying effects

Definition at line 224 of file CCNode.h.

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

If YES the transformtions will be relative to its 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.

Definition at line 255 of file CCNode.h.

- (BOOL) isRunning [read, assign]

whether or not the node is running

Definition at line 248 of file CCNode.h.

- (NSUInteger) orderOfArrival [read, write, assign]

used internally for zOrder sorting, don't change this manually

Definition at line 269 of file CCNode.h.

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

A weak reference to the parent

Definition at line 250 of file CCNode.h.

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

Position (x,y) of the node in points. (0,0) is the left-bottom corner.

Definition at line 218 of file CCNode.h.

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

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

Definition at line 210 of file CCNode.h.

- (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.

Definition at line 212 of file CCNode.h.

- (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.

Definition at line 214 of file CCNode.h.

- (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.

Definition at line 216 of file CCNode.h.

- (CCScheduler*) scheduler [read, write, retain]

CCScheduler used to schedule all "updates" and timers. IMPORTANT: If you set a new CCScheduler, then previously created timers/update are going to be removed.

Since:
v2.0

Definition at line 286 of file CCNode.h.

- (CCGLProgram*) shaderProgram [read, write, retain]

Shader Program

Since:
v2.0

Definition at line 266 of file CCNode.h.

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

The X skew angle of the node in degrees. This angle describes the shear distortion in the X direction. Thus, it is the angle between the Y axis and the left edge of the shape The default skewX angle is 0. Positive values distort the node in a CW direction.

Definition at line 201 of file CCNode.h.

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

The Y skew angle of the node in degrees. This angle describes the shear distortion in the Y direction. Thus, it is the angle between the X axis and the bottom edge of the shape The default skewY angle is 0. Positive values distort the node in a CCW direction.

Definition at line 208 of file CCNode.h.

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

A tag used to identify the node easily

Definition at line 257 of file CCNode.h.

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

A custom user data pointer

Definition at line 259 of file CCNode.h.

- (id) userObject [read, write, retain]

Similar to userData, but instead of holding a void* it holds an id

Definition at line 261 of file CCNode.h.

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

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

  • OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children
  • OpenGL Z might require to set 2D projection
  • cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0
    Warning:
    : Use it at your own risk since it might break the cocos2d parent-children z order
    Since:
    v0.8

Definition at line 194 of file CCNode.h.

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

Whether of not the node is visible. Default is YES

Definition at line 226 of file CCNode.h.

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

The z order of the node relative to its "siblings": children of the same parent

Definition at line 185 of file CCNode.h.


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

cocos2d for iPhone API Reference - Generated using Doxygen 1.8.0