Inherits from | CCResponder : NSObject |
Conforms to | CCSchedulerTarget |
Declared in | CCNode.h |
CCNode is the base class for all objects displayed by Cocos2D. CCNode handles transformations, can have a content size and provides a coordinate system for its child nodes.
CCNode是所有被Cocos2D显示的对象的基础类。CCNode处理转换,可以有内容的尺寸和提供为子nodes提供坐标系统.
Nodes are hierachically organized in a tree with a CCScene as its root node. This is often referred to as scene graph, node hierarchy or node tree.
By default every node can have other nodes as child nodes. Some node classes restrict child nodes to a specific instance type, or don’t allow child nodes at all.
默认任何node都可以有子node,有些node类限制子node为特定类型或者根本不允许有子node。
A child node is positioned and rotated relative to its parent. Some properties of the parent node are “inherited” by child nodes, for example: scale,visible, paused. Other properties are only “inherited” if enabled, see cascadeOpacityEnabled for example.
子node的位置和旋转与父母node有关。
Draw order of nodes is controlled primarily by their order in the node hierarchy. The parent node is drawn first, followed by its child nodes in the order they were added.
You can fine-tune draw order via the zOrder property. By default all nodes have a zOrder of 0. Nodes with lower zOrder are drawn before nodes with higher zOrder. This applies only to nodes in the same level (sibling nodes) and their parent node, as the zOrder is relative to the zOrder of the parent.
Assuming you have two parent nodes A and B with zOrder 0 and they are drawn in the order A first, then B. Then all of the children of parent B will be drawn in front of any child node of parent A. If B’s zOrder is changed to -1, then parent B and all of its children will be drawn behind parent A and itschildren.
Implementing a method with a signature of -(void) update:(CCTime)delta
in a CCNode subclass will have that method run once every frame.CCTime
is declared as double
.
If this doesn’t suffice you can use the various schedule methods of a node, such as schedule:interval: or scheduleBlock:delay:. For example the following selector runs once every second:
[self schedule:@selector(everySecond:) interval:1.0];
The signature of scheduled selectors is always the same with a single CCTime parameter and no return value:
-(void) everySecond:(CCTime)delta {
NSLog(@"tic-toc ..");
}
Warning: Any non-Cocos2D scheduling methods will be unaffected by the node’s paused state and may run in indeterminate order, possibly causing rendering glitches and timing bugs. It is therfore strongly discouraged to use NSTimer, performSelector:afterDelay:
or Grand Central Disptach (GCD) dispatch_xxx
methods to time/schedule tasks in Cocos2D.
It is common practice to pause the topmost node of a layer whose contents you want to pause. For instance you should have a gameLayer node that you can use to pause the entire game, while the hudLayer and pauseMenuLayer nodes may not need to or shouldn’t be paused in order to continue animations and allowing the user to interact with a pause menu.
Any CCNode or subclass can receive touch and mouse events, if enabled. See the CCResponder super class for more information.
Coordinates in the CCNode coordinate system are by default set in points by the position property. The point measurement provides a way to handle different screen pixel densities. For instance, on a Retina device one point corresponds to two pixels, but on non-Retina devices point and pixel resolution are identical.
By using the positionType property you can specify how a node’s position is interpreted. For instance, if you set the type to CCPositionTypeNormalized a position value of (0.5, 0.5) will place the node in the center of its parent’s container. The container is specified by the parent’s contentSize.
It’s also possible to set positions relative to the different corners of the parent’s container. The CCPositionType has three components, xUnit, yUnit and corner. The corner can be any reference corner of the parent’s container and the xUnit and yUnit can be any of the following:
Similarily to how you set a node’s position and positionType you can also set it’s contentSize and contentSizeType. However, some classes doesn’t allow you to set these directly. For instance, the CCSprite sets its contentSize depending on the size of its texture and for descendants of CCControlyou should set the preferredSize and preferredSizeType rather than changing their contentSize directly. The CCSizeType has two components widthUnit and heightUnit which can be any of the following:
Even if the positions and content sizes are not set in points you can use actions to animate the nodes. See the examples and tests for more information on how to set positions and content sizes, or use SpriteBuilder to easily play around with the settings. There are also more positioning options available by using CCLayout and CCLayoutBox.
There are typically two properties of each property supporting a “type”. For instance the position property returns the raw values whose meaning depends on positionType, while positionInPoints will return the position in points regardless of positionType. It is recommended to use the “inPoints” variants of properties if you expect the values to be in points.
Otherwise your code will break if you subsequently change the positionType to something other than points (ie UIPoints or Normalized).
A common pattern in building a Cocos2d game is to subclass CCNode, add it to a CCScene and override the methods for handling user input. Consider each node subclass as being the view in a MVC model, but it’s also the controller for this node and perhaps even the node’s branch of the node tree. The model can also be represented by the node subclass itself, or made separate (M-VC model).
A separate model could simply be any NSObject class initialized by the node subclass and assigned to an ivar/property.
An advanced subclassing style aims to minimize subclassing node classes except for CCNode itself. A CCNode subclass acts as the controller for itsnode tree, with one or more child nodes representing the controller node’s views. This is particularly useful for composite nodes, such as a player with multiple body parts (head, torso, limbs), attachments (armor, weapons) and effects (health bar, name label, selection rectangle, particle effects).
The userObject property can be used to add custom data and methods (model, components) to any node, in particular to avoid subclassing where the subclass would only add minimal functionality or just data.
userObject
property position
property positionInPoints
property positionType
property rotation
property rotationalSkewX
property rotationalSkewY
property skewX
property skewY
property scale
property scaleX
property scaleY
property scaleInPoints
property scaleXInPoints
property scaleYInPoints
property scaleType
property contentSize
property contentSizeInPoints
property contentSizeType
property– viewDidResizeTo:
– boundingBox
anchorPoint
property anchorPointInPoints
property– addChild:
– addChild:z:
– addChild:z:name:
– removeFromParent
– removeChild:
– removeChildByName:
– removeAllChildren
parent
property children
property scene
property– removeFromParentAndCleanup:
– removeChild:cleanup:
– removeChildByName:cleanup:
– removeAllChildrenWithCleanup:
name
property– getChildByName:recursively:
paused
property runningInActiveScene
property– runAction:
– stopAllActions
– stopAction:
– stopActionByTag:
– getActionByTag:
– numberOfRunningActions
animationManager
property– scheduleBlock:delay:
– schedule:interval:
– schedule:interval:repeat:delay:
– reschedule:interval:
– scheduleOnce:delay:
– unschedule:
– unscheduleAllSelectors
– convertPositionToPoints:type:
– convertPositionFromPoints:type:
– convertContentSizeToPoints:type:
– convertContentSizeFromPoints:type:
– convertToNodeSpace:
– convertToWorldSpace:
– convertToNodeSpaceAR:
– convertToWorldSpaceAR:
– convertToWindowSpace:
color
property colorRGBA
property displayedColor
property cascadeColorEnabled
property opacity
property displayedOpacity
property cascadeOpacityEnabled
property physicsBody
propertyThe anchorPoint is the point around which all transformations (scale, rotate) and positioning manipulations take place. The anchorPoint is normalized, like a percentage. (0,0) refers to the bottom-left corner and (1,1) refers to the top-right corner. The default anchorPoint is (0,0). It starts in the bottom-left corner. CCSprite and some other node subclasses may have a different default anchorPoint, typically centered on the node (0.5,0.5).
@property (nonatomic, readwrite) CGPoint anchorPoint
CCNode.h
The anchorPoint in absolute points. It is calculated as follows: x =
contentSizeInPoints.width *
anchorPoint.x; y =
contentSizeInPoints.height *
anchorPoint.y;
@property (nonatomic, readonly) CGPoint anchorPointInPoints
Note: The returned point is relative to the node’s contentSize origin, not relative to the node’s position.
CCNode.h
@property (nonatomic, readonly) CCAnimationManager *animationManager
Note: The animationManager property is nil during a node’s init methods.
CCNode.h
CascadeColorEnabled causes changes to this node’s color to cascade down to it’s children. The new color is multiplied in with the color of each child, so it doesn’t bash the current color of those nodes. Opacity is unaffected by this property, see cascadeOpacityEnabled to change the alpha of nodes.
@property (nonatomic, getter=isCascadeColorEnabled) BOOL cascadeColorEnabled
CCNode.h
CascadeOpacity causes changes to this node’s opacity to cascade down to it’s children. The new opacity is multiplied in with the opacity of each child, so it doesn’t bash the current opacity of those nodes. Color is unaffected by this property. See cascadeColorEnabled for color changes.
@property (nonatomic, getter=isCascadeOpacityEnabled) BOOL cascadeOpacityEnabled
CCNode.h
Array of child nodes. Used to enumerate child nodes, for instance the following allows you to perform a task on all child nodes with a matching name:
@property (nonatomic, readonly) NSArray *children
for (CCNode* child in self.children)
{
if ([child.name isEqualToString:@"so we meet again"])
{
// do stuff here ...
}
}
CCNode.h
Sets and returns the node’s color. Alpha is ignored. Changing color has no effect on nonvisible nodes (ie CCNode, CCScene).
@property (nonatomic, strong) CCColor *color
Note: By default color is not “inherited” by child nodes. This can be enabled via cascadeColorEnabled.
CCNode.h
Sets and returns the node’s color including alpha. Changing color has no effect on nonvisible nodes (ie CCNode, CCScene).
@property (nonatomic, strong) CCColor *colorRGBA
Note: By default color is not “inherited” by child nodes. This can be enabled via cascadeColorEnabled.
CCNode.h
The untransformed size of the node in the unit specified by contentSizeType property. The contentSize remains the same regardless of whether thenode is scaled or rotated.
@property (nonatomic, readwrite, assign) CGSize contentSize
CCNode.h
The untransformed size of the node in Points. The contentSize remains the same regardless of whether the node is scaled or rotated. contentSizeInPoints will be scaled by the [CCDirector UIScaleFactor] if the contentSizeType is CCSizeUnitUIPoints.
@property (nonatomic, readwrite, assign) CGSize contentSizeInPoints
CCNode.h
Defines the contentSize type used for the width and height components of the contentSize property.
@property (nonatomic, readwrite, assign) CCSizeType contentSizeType
CCNode.h
Returns the actual color used by the node. This may be different from the color and colorRGBA properties if the parent node has cascadeColorEnabled.
@property (nonatomic, readonly) CCColor *displayedColor
CCNode.h
Returns the actual opacity, in the range 0.0 to 1.0. This may be different from the opacity property if the parent node has cascadeOpacityEnabled.
@property (nonatomic, readonly) CGFloat displayedOpacity
CCNode.h
A name tag used to help identify the node easily. Can be used both to encode custom data but primarily meant to obtain a node by its name.
@property (nonatomic, strong) NSString *name
CCNode.h
Sets and returns the opacity in the range 0.0 (fully transparent) to 1.0 (fully opaque).
@property (nonatomic) CGFloat opacity
Note: By default opacity is not “inherited” by child nodes. This can be enabled via cascadeOpacityEnabled.
Warning: If the the texture has premultiplied alpha then the RGB channels will be modified.
CCNode.h
A weak reference to the parent.
@property (nonatomic, readwrite, weak) CCNode *parent
Warning: Never ever change the parent manually! This must be done exclusively by Cocos2D. This property is not readonly due to historical reasons, and this is prone to change.
CCNode.h
If paused is set to YES, all of the node’s actions and its scheduled selectors/blocks will be paused until the node is unpaused.
@property (nonatomic, assign) BOOL paused
Changing the paused state of a node will also change the paused state of its children recursively.
Warning: Any non-Cocos2D scheduling methods will be unaffected by the paused state. It is strongly discouraged to use NSTimer,performSelector:afterDelay:
or Grand Central Disptach (GCD) dispatch_xxx
methods to time/schedule tasks in Cocos2D.
CCNode.h
The physics body (if any) that this node is attached to. Initialize and assign a CCPhysicsBody instance to this property to have the node participate in the physics simulation.
@property (nonatomic, strong) CCPhysicsBody *physicsBody
CCNode.h
Position (x,y) of the node in the units specified by the positionType property. The distance is measured from one of the corners of the node’s parentcontainer, which corner is specified by the positionType property. Default setting is referencing the bottom left corner in points.
@property (nonatomic, readwrite, assign) CGPoint position
CCNode.h
Position (x,y) of the node in points from the bottom left corner.
@property (nonatomic, readwrite, assign) CGPoint positionInPoints
CCNode.h
Defines the position type used for the position property. Changing the position type affects the meaning of the values assigned to the position property and allows you to change the referenceCorner relative to the parent container. It also allows position to be interpreted as “UIPoints”, which are scaled by[CCDirector UIScaleFactor]. See “Coordinate System and Positioning” in Class Overview for more information.
@property (nonatomic, readwrite, assign) CCPositionType positionType
CCNode.h
The rotation (angle) of the node in degrees. Rotation is relative to the parent node’s rotation. 0 is the default rotation angle. Positive values rotate nodeclockwise.
@property (nonatomic, readwrite, assign) float rotation
CCNode.h
The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node clockwise. It only modifies the X rotationperforming a horizontal rotational skew.
@property (nonatomic, readwrite, assign) float rotationalSkewX
CCNode.h
The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node clockwise. It only modifies the Y rotationperforming a vertical rotational skew.
@property (nonatomic, readwrite, assign) float rotationalSkewY
CCNode.h
Returns YES if the node is added to an active scene and neither it nor any of it’s ancestors is paused.
@property (nonatomic, readonly, getter=isRunningInActiveScene) BOOL runningInActiveScene
CCNode.h
The scale factor of the node. 1.0 is the default scale factor (original size). Meaning depends on scaleType. It modifies the X and Y scale at the same time, preserving the node’s aspect ratio.
@property (nonatomic, readwrite, assign) float scale
Scale is affected by the parent node’s scale, ie if parent’s scale is 0.5 then setting the child’s scale to 2.0 will make the child node appear at its original size.
CCNode.h
The scaleInPoints is the scale factor of the node in both X and Y, measured in points. The scaleType property indicates if the scaleInPoints will be scaled by the UIScaleFactor or not. See “Coordinate System and Positioning” in class overview for more information.
@property (nonatomic, readonly) float scaleInPoints
Scale is affected by the parent node’s scale, ie if parent’s scale is 0.5 then setting the child’s scale to 2.0 will make the child node appear at its original size.
CCNode.h
The scaleType defines scale behavior for this node. CCScaleTypeScaled indicates that the node will be scaled by [CCDirector UIScaleFactor]. This property is analagous to positionType. ScaleType affects the scaleInPoints of a CCNode. See “Coordinate System and Positioning” in class overview for more information.
@property (nonatomic, assign) CCScaleType scaleType
CCNode.h
@property (nonatomic, readwrite, assign) float scaleX
Scale is affected by the parent node’s scale, ie if parent’s scale is 0.5 then setting the child’s scale to 2.0 will make the child node appear at its original size.
CCNode.h
The scaleInPoints is the scale factor of the node in X, measured in points.
@property (nonatomic, readonly) float scaleXInPoints
Scale is affected by the parent node’s scale, ie if parent’s scale is 0.5 then setting the child’s scale to 2.0 will make the child node appear at its original size.
CCNode.h
@property (nonatomic, readwrite, assign) float scaleY
Scale is affected by the parent node’s scale, ie if parent’s scale is 0.5 then setting the child’s scale to 2.0 will make the child node appear at its original size.
CCNode.h
The scaleInPoints is the scale factor of the node in Y, measured in points.
@property (nonatomic, readonly) float scaleYInPoints
Scale is affected by the parent node’s scale, ie if parent’s scale is 0.5 then setting the child’s scale to 2.0 will make the child node appear at its original size.
CCNode.h
The scene this node is added to, or nil if it’s not part of a scene.
@property (nonatomic, readonly) CCScene *scene
CCNode.h
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, with valid ranges from -90 to 90. Positive values distort the node in a clockwise direction.
@property (nonatomic, readwrite, assign) float skewX
CCNode.h
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, with valid ranges from -90 to 90. Positive values distort the node in a counter-clockwise direction.
@property (nonatomic, readwrite, assign) float skewY
CCNode.h
Used to store a custom object of any type. For instance you could add a NSMutableDictionary to store custom data in a node without needing to subclass the node.
@property (nonatomic, readwrite, strong) id userObject
CCNode.h
@property (nonatomic, readwrite, assign) BOOL visible
Note: The children nodes will not change their visible property. Nevertheless they won’t be drawn if their parent’s visible property is NO. This means even if a node’s visible property may be YES it could still be invisible if one of its parents has visible set to NO.
Note: Nodes that are not visible will not be rendered. For recurring use of the same nodes it is typically more efficient to temporarily setnode
.visible = NO
compared to removeFromParent and a subsequent addChild:.
CCNode.h
The draw order of the node relative to its sibling (having the same parent) nodes. The default is 0.
@property (nonatomic, assign) NSInteger zOrder
A zOrder of less than 0 will draw nodes behind their parent, a zOrder of 0 or greater will make the nodes draw in front of their parent.
A parent nodes with a lower zOrder value will have itself and its children drawn behind another parent node with a higher zOrder value. The zOrder property only affects sibling nodes and their parent, it can not be used to change the draw order of nodes with different parents - in that case adjust the parent node’s zOrder.
Note: Any sibling nodes with the same zOrder will be drawn in the order they were added as children. It is slightly more efficient (and certainly less confusing) to make this natural order work to your advantage.
CCNode.h
Adds a child to the container with default zOrder (0). If the child is added to a ‘running’ node, then ‘onEnter’ and ‘onEnterTransitionDidFinish’ will be sent to the node immediately.
- (void)addChild:(CCNode *)node
CCNode to add as a child.
CCNode.h
Adds a child to the container with the given zOrder. If the child is added to a ‘running’ node, then ‘onEnter’ and ‘onEnterTransitionDidFinish’ will be sent to the node immediately.
- (void)addChild:(CCNode *)node z:(NSInteger)z
CCNode to add as a child.
CCNode.h
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.
- (void)addChild:(CCNode *)node z:(NSInteger)z name:(NSString *)name
CCNode to add as a child.
CCNode.h
Returns an axis aligned bounding box in points, in the parent node’s coordinate system.
- (CGRect)boundingBox
CCNode.h
Converts the given size in points to size values converted based on the provided CCSizeType.
- (CGSize)convertContentSizeFromPoints:(CGSize)pointSize type:(CCSizeType)type
The size in points to convert.
How the input size values should be converted.
The size values in the format specified by type.
CCSizeType, CCSizeUnit
CCNode.h
Converts the given content size values to a size in points.
- (CGSize)convertContentSizeToPoints:(CGSize)contentSize type:(CCSizeType)type
The contentSize values to convert.
How the input contentSize values should be interpreted.
The converted size in points.
CCSizeType, CCSizeUnit
CCNode.h
Converts the given position in points to position values converted based on the provided CCPositionType.
- (CGPoint)convertPositionFromPoints:(CGPoint)positionInPoints type:(CCPositionType)type
The position in points to convert.
How the input position values should be converted.
The position values in the format specified by type.
CCPositionType, CCPositionUnit, CCPositionReferenceCorner
CCNode.h
- (CGPoint)convertPositionToPoints:(CGPoint)position type:(CCPositionType)type
The position values to convert.
How the input position values should be interpreted.
The converted position in points.
CCPositionType, CCPositionUnit, CCPositionReferenceCorner
CCNode.h
Converts a Point to node (local) space coordinates. The result is in Points.
- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint
World position in points.
Local position in points.
CCNode.h
Converts a Point to node (local) space coordinates. The result is in Points. Treats the returned/received node point as relative to the anchorPoint.
- (CGPoint)convertToNodeSpaceAR:(CGPoint)worldPoint
World position in points.
Local position in points.
CCNode.h
Converts a local Point to Window space (UIKit) coordinates. The result is in Points.
- (CGPoint)convertToWindowSpace:(CGPoint)nodePoint
Local position in points.
UI position in points.
CCNode.h
Converts a Point to world space coordinates. The result is in Points.
- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint
Local position in points.
World position in points.
CCNode.h
Converts a local Point to world space coordinates. The result is in Points. Treats the returned/received node point as relative to the anchorPoint.
- (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint
Local position in points.
World position in points.
CCNode.h
Override this method to add custom rendering code to your node.
- (void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
The CCRenderer instance to use for drawing.
The parent node’s transform.
Note: You should only use Cocos2D’s CCRenderer API to modify the render state and shaders. For further info, please see the CCRendererdocumentation.
Warning: You must not call [super draw:transform:];
CCNode.h
Gets an action running on the node given its tag. If there are multiple actions with the same tag it will get the first action found that has this tag.
- (CCAction *)getActionByTag:(NSInteger)tag
Tag of an action.
The first action with the given tag, or nil if there’s no running action with this tag.
CCNode.h
Search through the children of the container for one matching the name tag. If recursive, it returns the first matching node, via a depth first search. Otherwise, only immediate children are checked.
- (CCNode *)getChildByName:(NSString *)name recursively:(bool)isRecursive
Returns the first node with a matching name, or nil if no node with that name was found.
Note: Avoid calling this often, ie multiple times per frame, as the lookup cost can add up. Specifically if the search is recursive.
CCNode.h
Returns the matrix that transform the node’s (local) space coordinates into the parent’s space coordinates. The matrix is in Pixels.
- (CGAffineTransform)nodeToParentTransform
CCNode.h
Returns the world affine transform matrix. The matrix is in Pixels.
- (CGAffineTransform)nodeToWorldTransform
CCNode.h
Returns the numbers of actions that are running plus the ones that are scheduled to run (actions in the internal actionsToAdd array).
- (NSUInteger)numberOfRunningActions
Note: Composable actions are counted as 1 action. Example: - If you are running 2 Sequences each with 7 actions, it will return 2. - If you are running 7 Sequences each with 2 actions, it will return 7.
CCNode.h
Called every time the CCNode (or one of its parents) has been added to the scene, or when the scene is presented. If a new scene is presented with a transition, this event is sent to nodes when the transition animation starts.
- (void)onEnter
Warning: You must call [super onEnter]
in your own implementation.
CCNode.h
Called every time the CCNode (or one of its parents) has been added to the scene, or when the scene is presented. If a new scene is presented with a transition, this event is sent to nodes after the transition animation ended. Otherwise it will be called immediately after onEnter.
- (void)onEnterTransitionDidFinish
Warning: You must call [super onEnterTransitionDidFinish]
in your own implementation.
CCNode.h
Called every time the CCNode is removed from the node tree. If a new scene is presented with a transition, this event is sent when the transition animation ended.
- (void)onExit
Warning: You must call [super onExit]
in your own implementation.
CCNode.h
Called every time the CCNode is removed from the node tree. If a new scene is presented with a transition, this event is sent when the transition animation starts.
- (void)onExitTransitionDidStart
Warning: You must call [super onExitTransitionDidStart]
in your own implementation.
CCNode.h
Returns the matrix that transform parent’s space coordinates to the node’s (local) space coordinates. The matrix is in Pixels.
- (CGAffineTransform)parentToNodeTransform
CCNode.h
Nearest CCPhysicsNode ancestor of this node, or nil if none. Unlike [CCPhysicsBody physicsNode], this will return a value before onEnter is called on thenode.
- (CCPhysicsNode *)physicsNode
CCPhysicsNode.h
Removes all children from the container.
- (void)removeAllChildren
CCNode.h
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
- (void)removeAllChildrenWithCleanup:(BOOL)cleanup
If YES, stops all scheduled events and actions of removed node.
Note: Running [self removeAllChildrenWithCleanup:YES]
is identical to running [self removeAllChildren]
. You only need to use this method if you intend to not stop scheduler and actions, ie cleanup:NO
.
CCNode.h
Removes a child from the container. The node must be a child of this node. Will stop the node’s scheduled selectors/blocks and actions.
- (void)removeChild:(CCNode *)child
The child node to remove.
CCNode.h
Removes a child from the container. The node must be a child of this node. If cleanup is YES the node will also remove all of its actions and scheduled selectors/blocks.
- (void)removeChild:(CCNode *)node cleanup:(BOOL)cleanup
Note: Running [self removeChild:
node cleanup:YES]
is identical to running [self removeChild:node]
. You only need to use this method if you intend to not stop scheduler and actions, ie cleanup:NO
.
CCNode.h
Removes a child from the container by name. Does nothing if there’s no node with that name. Will stop the node’s scheduled selectors/blocks and actions.
- (void)removeChildByName:(NSString *)name
Name of node to be removed.
CCNode.h
Removes a child from the container by name value. If cleanup is YES the node will also remove all of its actions and scheduled selectors/blocks.
- (void)removeChildByName:(NSString *)name cleanup:(BOOL)cleanup
Note: Running [self removeChildByName:@"name" cleanup:YES]
is identical to running [self removeChildByName:@"name"]
. You only need to use this method if you intend to not stop scheduler and actions, ie cleanup:NO
.
CCNode.h
Removes the node from its parent node. If cleanup is YES the node will also remove all of its actions and scheduled selectors/blocks.
- (void)removeFromParentAndCleanup:(BOOL)cleanup
Note: Running [self removeFromParentAndCleanup:YES]
is identical to running [self removeFromParent]
. You only need to use this method if you intend to not stop scheduler and actions, ie cleanup:NO
.
CCNode.h
Re-schedules a custom selector with an interval time in seconds. If the custom selector you pass in is not already scheduled, this method is equivalent to schedule:interval:.
The difference between this method and schedule:interval: is that if the selector is already scheduled, calling this method will only adjust the interval of the already scheduled selector.
- (CCTimer *)reschedule:(SEL)selector interval:(CCTime)interval
Selector to run. The selector must have the following signature: -(void) theSelector:(CCTime)delta
where theSelector is any legal selectorname. The parameter must be specified with the @selector keyword as @selector(theSelector:)
.
Interval between execution in seconds.
In contrast, when you call schedule:interval: on an already scheduled selector, your custom selector will be unscheduled and then rescheduled which is less efficient.
CCNode.h
Has the node run an action.
- (CCAction *)runAction:(CCAction *)action
Action to run.
The action that is executed (same as the one that was passed in).
Note: Depending on when in the frame update cycle this method gets called, the action passed in may either start running in the current frame or in the next frame.
CCNode.h
Schedules a custom selector to run repeatedly at the given interval (in seconds). If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
- (CCTimer *)schedule:(SEL)selector interval:(CCTime)seconds
Selector to run. The selector must have the following signature: -(void) theSelector:(CCTime)delta
where theSelector is any legal selectorname. The parameter must be specified with the @selector keyword as @selector(theSelector:)
.
Interval between executions in seconds.
A newly initialized CCTimer object.
Note: If interval is 0 the selector will run once every frame. It is recommended and slightly more efficient to implement the update: method instead. If the update: method is already implemented, just call a selector from update: that runs whatever selector you wanted to schedule with interval 0.
CCNode.h
Schedules a custom selector to run repeatedly at the given interval (in seconds).
- (CCTimer *)schedule:(SEL)selector interval:(CCTime)interval repeat:(NSUInteger)repeat delay:(CCTime)delay
Selector to run. The selector must have the following signature: -(void) theSelector:(CCTime)delta
where theSelector is any legal selectorname. The parameter must be specified with the @selector keyword as @selector(theSelector:)
.
Interval between executions in seconds.
Number of times to repeat the selector. The selector will run repeat times plus one because the first run is not considered a “repeat”.
Delay before running the selector for the first time, in seconds.
A newly initialized CCTimer object.
CCNode.h
Schedules a block to run once, after the given delay.
- (CCTimer *)scheduleBlock:(CCTimerBlock)block delay:(CCTime)delay
Block to execute. The block takes a CCTimer*
parameter as input and returns nothing.
Delay, in seconds.
A newly initialized CCTimer object.
CCTimerBlock
is a block typedef declared as void (^)(
CCTimer *timer)
Note: There is currently no way to stop/cancel an already scheduled block. If a scheduled block should not run under certain circumstances, the block’s code itself must check these conditions to determine whether it should or shouldn’t perform its task.
CCNode.h
Schedules a selector that runs only once, with an initial delay.
- (CCTimer *)scheduleOnce:(SEL)selector delay:(CCTime)delay
Selector to run. The selector must have the following signature: -(void) theSelector:(CCTime)delta
where theSelector is any legal selectorname. The parameter must be specified with the @selector keyword as @selector(theSelector:)
.
Delay before selector runs, in seconds.
A newly initialized CCTimer object.
CCNode.h
Removes an action from the running action list.
- (void)stopAction:(CCAction *)action
Action to remove.
CCNode.h
Removes an action from the running action list given its tag. If there are multiple actions with the same tag it will only remove the first action found that has this tag.
- (void)stopActionByTag:(NSInteger)tag
Tag of action to remove.
CCNode.h
Stops and removes all actions running on the node. @node It is not necessary to call this when removing a node. Removing a node from its parent will also stop its actions.
- (void)stopAllActions
CCNode.h
Unschedule an already scheduled selector. Does nothing if the given selector isn’t scheduled.
- (void)unschedule:(SEL)selector
Selector to unschedule. The parameter must be specified with the @selector keyword as @selector(theSelector:)
.
CCNode.h
Unschedules all scheduled selectors.
- (void)unscheduleAllSelectors
CCNode.h
Invoked automatically when the OS view has been resized.
- (void)viewDidResizeTo:(CGSize)newViewSize
The new size of the view after it has been resized.
This implementation simply propagates the same method to the children. Subclasses may override to actually do something when the view resizes.
CCNode.h
Prints on the debug console the scene graph
- (void)walkSceneGraph:(NSUInteger)level
Level of debug information.
CCNode+Debug.h
CCNode Class-----Cocos2D-Swift v3.3
原文:http://www.cnblogs.com/somebod-Y/p/4266193.html