CCNode Class Reference
#import <CCNode.h>
Inherited by CCAtlasNode, CCLayer, CCMenuItem, CCMotionStreak, CCParallaxNode, CCParticleSystem, CCRenderTexture, CCRibbon, CCScene, CCSprite, CCSpriteSheet, and CCTMXTiledMap.
List of all members.
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:
- They can contain other CCnode nodes (addChild, getChildByTag, removeChild, etc)
- They can schedule periodic callback (schedule, unschedule, etc)
- They can execute actions (runAction, stopAction, etc)
Some CCNode nodes provide extra functionality for them or their children.
Subclassing a CCNode usually means (one/all) of:
- overriding init to initialize resources and schedule callbacks
- create callbacks to handle the advancement of time
- overriding draw to render the node
Features of CCNode:
- position
- scale (x, y)
- rotation (in degrees)
- Camera ( using spherical coordinates )
- GridBase (to do mesh transformations)
- anchor point
- size
- visible
- z-order
- openGL z position
Default values:
- rotation: 0
- position: (x=0,y=0)
- scale: (x=1,y=1)
- contentSize: (x=0,y=0)
- anchorPoint: (x=0,y=0)
Limitations:
- A CCNode is a "void" object. It doesn't have a texture
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:
- Each node has a camera. By default it points to the center of the CCNode.
Definition at line 85 of file CCNode.h.
Member Function Documentation
activate all scheduled timers. Called internally by onEnter
| - (id) addChild: |
|
(CCNode *) |
node |
|
|
Adds a child to the container with z-order as 0. It returns self, so you can chain several addChilds.
- Since:
- v0.7.1
| - (id) addChild: |
|
(CCNode *) |
node |
| z: |
|
(int) |
z | |
|
|
| | |
Adds a child to the container with a z-order It returns self, so you can chain several addChilds.
- Since:
- v0.7.1
| - (id) addChild: |
|
(CCNode *) |
node |
| z: |
|
(int) |
z |
| tag: |
|
(int) |
tag | |
|
|
| | |
Adds a child to the container with z order and tag It returns self, so you can chain several addChilds.
- Since:
- v0.7.1
returns an axis aligned bounding box of the node. It takes into account any kind of transformation.
- Since:
- v0.8.2
Returns the array that contains all the children
Stops all running actions and schedulers
- Since:
- v0.8
| - (CGPoint) convertToNodeSpace: |
|
(CGPoint) |
worldPoint |
|
|
converts a world coordinate to local coordinate
- Since:
- v0.7.1
| - (CGPoint) convertToNodeSpaceAR: |
|
(CGPoint) |
worldPoint |
|
|
converts a world coordinate to local coordinate treating the returned/received node point as anchor relative
- Since:
- v0.7.1
| - (CGPoint) convertTouchToNodeSpace: |
|
(UITouch *) |
touch |
|
|
convenience methods which take a UITouch instead of CGPoint
- Todo:
- convertTouchToNodeSpace needs documentation
- Since:
- v0.7.1
| - (CGPoint) convertTouchToNodeSpaceAR: |
|
(UITouch *) |
touch |
|
|
- Todo:
- convertTouchToNodeSpaceAR needs documentation
- Since:
- v0.7.1
| - (CGPoint) convertToWorldSpace: |
|
(CGPoint) |
nodePoint |
|
|
converts local coordinate to world space
- Since:
- v0.7.1
| - (CGPoint) convertToWorldSpaceAR: |
|
(CGPoint) |
nodePoint |
|
|
converts local coordinate to world space treating the returned/received node point as anchor relative
- Since:
- v0.7.1
| - (void) deactivateTimers |
|
|
|
|
deactivate all scheduled timers. Called internally by onExit
override this method to draw your own node.
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
allocates and initializes a node. The node will be created as "autorelease".
| - (CGAffineTransform) nodeToParentTransform |
|
|
|
|
actual affine transforms used
- Todo:
- nodeToParentTransform needs documentation
- Since:
- v0.7.1
| - (CGAffineTransform) nodeToWorldTransform |
|
|
|
|
- Todo:
- nodeToWorldTransform needs documentation
- 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.
callback that is called every time the CCNode enters the 'stage'. If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts. During onEnter you can't a "sister/brother" node.
| - (void) onEnterTransitionDidFinish |
|
|
|
|
callback that is called when the CCNode enters in the 'stage'. If the CCNode enters the 'stage' with a transition, this callback is called when the transition finishes.
- Since:
- v0.8
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 finishes. During onExit you can't a "sister/brother" node.
| - (CGAffineTransform) parentToNodeTransform |
|
|
|
|
- Todo:
- parentToNodeTransform needs documentation
- Since:
- v0.7.1
| - (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) reorderChild: |
|
(CCNode *) |
child |
| z: |
|
(int) |
zOrder | |
|
|
| | |
Reorders a child according to a new z value. The child MUST be already added.
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 |
|
|
check whether a selector is scheduled. schedules a selector. The scheduled selector will be ticked every frame
| - (void) schedule: |
|
(SEL) |
s |
| interval: |
|
(ccTime) |
seconds | |
|
|
| | |
schedules a selector with an interval time in seconds. If time is 0 it will be ticked every frame.
| - (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
Removes all actions from the running action list
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 |
|
|
recursive method that visit its children and draw them
| - (CGAffineTransform) worldToNodeTransform |
|
|
|
|
- Todo:
- worldToNodeTransform needs documentation
- 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 is (0.5,0.5), so it starts in the center of the node.
- Since:
- v0.8
Definition at line 184 of file CCNode.h.
- (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
Definition at line 188 of file CCNode.h.
A Camera object that lets you move the node using camera coordinates. If you use the Camera then position, scale & rotation won't be used
Definition at line 172 of file CCNode.h.
- (CGSize) contentSize [read, write, assign] |
The untransformed size of the node. 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 195 of file CCNode.h.
A Grid object that is used when applying Effects
Definition at line 174 of file CCNode.h.
- (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.
Definition at line 204 of file CCNode.h.
- (BOOL) isRunning [read, assign] |
whether or not the node is running
Definition at line 197 of file CCNode.h.
- (CCNode*) parent [read, write, assign] |
A weak reference to the parent
Definition at line 199 of file CCNode.h.
- (CGPoint) position [read, write, assign] |
Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner.
Definition at line 169 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 161 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 163 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 165 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 167 of file CCNode.h.
- (int) tag [read, write, assign] |
A tag used to identify the node easily
Definition at line 206 of file CCNode.h.
- (void *) userData [read, write, assign] |
A custom user data pointer
Definition at line 136 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 159 of file CCNode.h.
- (BOOL) visible [read, write, assign] |
Whether of not the node is visible. Default is YES
Definition at line 176 of file CCNode.h.
- (int) zOrder [read, assign] |
The z order of the node relative to it's "brothers": children of the same parent
Definition at line 150 of file CCNode.h.
The documentation for this class was generated from the following file:
- /Users/riq/tmp/cocos2d-iphone-0.99.0/cocos2d/CCNode.h