![]() |
cocos2d-iphone
2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
|
#import <CCNode.h>
Public Member Functions | |
(id) | - init |
(void) | - onEnter |
(void) | - onEnterTransitionDidFinish |
(void) | - onExit |
(void) | - onExitTransitionDidStart |
(void) | - addChild: |
(void) | - addChild:z: |
(void) | - addChild:z:tag: |
(void) | - removeFromParent |
(void) | - removeFromParentAndCleanup: |
(void) | - removeChild: |
(void) | - removeChild:cleanup: |
(void) | - removeChildByTag: |
(void) | - removeChildByTag:cleanup: |
(void) | - removeAllChildren |
(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) | - unscheduleUpdate |
(void) | - schedule: |
(void) | - schedule:interval: |
(void) | - schedule:interval:repeat:delay: |
(void) | - scheduleOnce:delay: |
(void) | - unschedule: |
(void) | - unscheduleAllSelectors |
(void) | - resumeSchedulerAndActions |
(void) | - pauseSchedulerAndActions |
(void) | - update: |
(CGAffineTransform) | - nodeToParentTransform |
(CGAffineTransform) | - parentToNodeTransform |
(CGAffineTransform) | - nodeToWorldTransform |
(CGAffineTransform) | - worldToNodeTransform |
(CGPoint) | - convertToNodeSpace: |
(CGPoint) | - convertToWorldSpace: |
(CGPoint) | - convertToNodeSpaceAR: |
(CGPoint) | - convertToWorldSpaceAR: |
(CGPoint) | - convertTouchToNodeSpace: |
(CGPoint) | - convertTouchToNodeSpaceAR: |
(void) | - setIsRelativeAnchorPoint: |
(BOOL) | - DEPRECATED_ATTRIBUTE |
(void) | - setZOrder: |
Static Public Member Functions | |
(id) | + node |
Protected Attributes | |
float | _rotationX |
float | _rotationY |
float | _scaleX |
float | _scaleY |
float | _vertexZ |
CGPoint | _position |
float | _skewX |
float | _skewY |
CGPoint | _anchorPointInPoints |
CGPoint | _anchorPoint |
CGSize | _contentSize |
CGAffineTransform | _transform |
CGAffineTransform | _inverse |
BOOL | _isTransformDirty |
BOOL | _isInverseDirty |
CCCamera * | _camera |
CCGridBase * | _grid |
NSInteger | _zOrder |
CCArray * | _children |
CCNode * | _parent |
NSInteger | _tag |
void * | _userData |
id | _userObject |
CCGLProgram * | _shaderProgram |
ccGLServerState | _glServerState |
NSUInteger | _orderOfArrival |
CCScheduler * | _scheduler |
CCActionManager * | _actionManager |
BOOL | _isRunning |
BOOL | _visible |
BOOL | _ignoreAnchorPointForPosition |
BOOL | _isReorderChildDirty |
Properties | |
NSInteger | zOrder |
float | vertexZ |
float | skewX |
float | skewY |
float | rotation |
float | rotationX |
float | rotationY |
float | scale |
float | scaleX |
float | scaleY |
CGPoint | position |
CCCamera * | camera |
CCArray * | children |
CCGridBase * | grid |
BOOL | visible |
CGPoint | anchorPoint |
CGPoint | anchorPointInPoints |
CGSize | contentSize |
BOOL | isRunning |
CCNode * | parent |
BOOL | ignoreAnchorPointForPosition |
NSInteger | tag |
void * | userData |
id | userObject |
CCGLProgram * | shaderProgram |
NSUInteger | orderOfArrival |
ccGLServerState | glServerState |
CCActionManager * | actionManager |
CCScheduler * | scheduler |
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
Order in transformations with grid enabled
Camera:
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.
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.
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.
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.
- (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]
Implemented in CCMenuItem.
- (CGPoint) convertToNodeSpace: | (CGPoint) | worldPoint |
Converts a Point to node (local) space coordinates. The result is in Points.
- (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.
- (CGPoint) convertTouchToNodeSpace: | (UITouch *) | touch |
Converts a UITouch to node (local) space coordinates. The result is in Points.
- (CGPoint) convertTouchToNodeSpaceAR: | (UITouch *) | touch |
Converts a UITouch to node (local) space coordinates. The result is in Points. This method is AR (Anchor Relative)..
- (CGPoint) convertToWorldSpace: | (CGPoint) | nodePoint |
Converts a Point to world space coordinates. The result is in Points.
- (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.
- (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
- (CCNode*) getChildByTag: | (NSInteger) | tag |
- (id) init |
initializes the node
Implemented in CCTransitionTurnOffTiles, CCTransitionCrossFade, CCTransitionZoomFlipAngular, CCTransitionZoomFlipY, CCTransitionZoomFlipX, CCTransitionFlipAngular, CCTransitionFlipY, CCTransitionFlipX, CCTransitionShrinkGrow, CCParticleRain, CCTransitionJumpZoom, CCParticleSnow, CCTransitionRotoZoom, CCParticleSmoke, CCParticleExplosion, CCParticleSpiral, CCParticleMeteor, CCClippingNode, CCParticleFlower, CCParticleGalaxy, CCParticleSun, CCScene, CCParticleFireworks, and CCParticleFire.
+ (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.
- (CGAffineTransform) nodeToWorldTransform |
Returns the world affine transform matrix. The matrix is in Pixels.
- (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 |
- (void) onEnterTransitionDidFinish |
- (void) onExit |
- (void) onExitTransitionDidStart |
- (CGAffineTransform) parentToNodeTransform |
Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates. The matrix is in Pixels.
- (void) pauseSchedulerAndActions |
pauses all scheduled selectors and actions. Called internally by onExit
- (void) removeAllChildren |
Removes all children from the container forcing a cleanup.
- (void) removeAllChildrenWithCleanup: | (BOOL) | cleanup |
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
- (void) removeChild: | (CCNode *) | child |
Removes a child from the container forcing a cleanup
- (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.
- (void) removeChildByTag: | (NSInteger) | tag |
Removes a child from the container by tag value forcing a cleanup.
- (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
- (void) removeFromParent |
Remove itself from its parent node forcing a cleanup. If the node orphan, then nothing happens.
- (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.
- (void) reorderChild: | (CCNode *) | child | |
z: | (NSInteger) | zOrder | |
Reorders a child according to a new z value. The child MUST be already added.
- (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.
- (void) schedule: | (SEL) | s |
schedules a selector. The scheduled selector will be ticked every frame
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 "update" method could be scheduled per node.
- (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 "update" selector could be scheduled per node (You can't have 2 'update' selectors).
- (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
- (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 its ancestors. Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO) it is necessary to transform the ancestors again.
- (void) unschedule: | (SEL) | s |
unschedules a custom selector.
- (void) unscheduleAllSelectors |
unschedule all scheduled selectors: custom selectors, and the 'update' selector. Actions are not affected by this method.
- (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.
- (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.
- (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.
- (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
- (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.
- (ccGLServerState) glServerState [read, write, assign] |
GL server side state
- (CCGridBase*) grid [read, write, retain] |
A CCGrid object that is used when applying effects
- (BOOL) ignoreAnchorPointForPosition [read, write, assign] |
- (BOOL) isRunning [read, assign] |
whether or not the node is running
- (NSUInteger) orderOfArrival [read, write, assign] |
used internally for zOrder sorting, don't change this manually
- (CGPoint) position [read, write, assign] |
Position (x,y) of the node in points. (0,0) is the left-bottom corner.
- (float) rotation [read, write, assign] |
The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW.
- (float) rotationX [read, write, assign] |
The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. It only modifies the X rotation performing a horizontal rotational skew .
- (float) rotationY [read, write, assign] |
The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. It only modifies the Y rotation performing a vertical rotational skew .
- (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.
- (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.
- (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.
- (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.
- (CCGLProgram*) shaderProgram [read, write, retain] |
Shader Program
- (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.
- (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.
- (NSInteger) tag [read, write, assign] |
A tag used to identify the node easily
- (void*) userData [read, write, assign] |
A custom user data pointer
- (id) userObject [read, write, retain] |
Similar to userData, but instead of holding a void* it holds an id
- (float) vertexZ [read, write, assign] |
The real openGL Z vertex. Differences between openGL Z vertex and cocos2d Z order:
- (BOOL) visible [read, write, assign] |
Whether of not the node is visible. Default is YES
- (NSInteger) zOrder [read, write, assign] |
The z order of the node relative to its "siblings": children of the same parent