Node
Class of all entities in Fireball scenes.
Properties
active Boolean
The local active state of this node.
activeInHierarchy Boolean
Indicates whether this node is active in the scene.
_components Component[] private readOnly
_prefab PrefabInfo private
The PrefabInfo object
_persistNode Boolean private
If true, the node is an persist node which won't be destroyed during scene transition. If false, the node will be destroyed automatically when loading a new scene. Default is false.
__eventTargets EventTarget[] private
Register all related EventTargets, all event callbacks will be removed in _onPreDestroy
name String
Name of node
parent Node
The parent of the node.
_id String private
uuid
uuid String readOnly
The uuid for editor, will be stripped before building project
skewX Number
Skew x
skewY Number
Skew y
zIndex Number
Z order in depth which stands for the drawing order.
rotation Number
Rotation of node
rotationX Number
Rotation on x axis
scaleX Number
Scale on x axis
scaleY Number
Scale on y axis
x Number
x axis position of node.
y Number
y axis position of node.
children Node[] readOnly
All children nodes
childrenCount Number readOnly
All children nodes.
anchorX Number
Anchor point's position on x axis.
anchorY Number
Anchor point's position on y axis.
width Number
Width of node.
height Number
Height of node.
ignoreAnchor Boolean
Indicate whether ignore the anchor point property for positioning.
tag Number
Tag of node.
opacity Number
Opacity of node, default value is 255.
cascadeOpacity Boolean
Indicate whether node's opacity value affect its child nodes, default value is false.
color Color
Color of node, default value is white: (255, 255, 255).
_sizeProvider _ccsg.Node private
Current active scene graph node which provides content size.
position Vec2
position of node.
scale Number
Scale of node
_name String private
_objFlags Number private
isValid Boolean readOnly
Indicates whether the object is not yet destroyed
Methods
getComponent
(
-
typeOrClassName
)
Component
- typeOrClassName
addComponent
(
-
typeOrClassName
)
Component
- typeOrClassName
_addComponentAt
(
-
comp
-
index
)
private
- comp
- index
removeComponent
(
-
component
)
deprecated
- component
_getDependComponent
(
-
depended
)
cc.Component
private
- depended
name | type | description |
---|---|---|
depended
|
cc.Component |
returns:
on
(
-
type
-
callback
-
[target
]
)
Function
- type
- callback
- [target ]
Register an callback of a specific event type on Node. Use this method to register touch or mouse event permit propagation based on scene graph, you can propagate the event to the parents or swallow it by calling stopPropagation on the event. It's the recommended way to register touch/mouse event for Node, please do not use cc.eventManager directly for Node.
name | type | description |
---|---|---|
type
|
String |
A string representing the event type to listen for. |
callback
|
Function |
The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).
|
target
optional
|
Object |
The target to invoke the callback, can be null |
returns:
runAction
(
-
action
)
cc.Action
- action
Executes an action, and returns the action that is executed.
The node becomes the action's target. Refer to cc.Action's getTarget()
Calling runAction while the node is not active won't have any effect
name | type | description |
---|---|---|
action
|
cc.Action |
returns:
An Action pointer
stopAllActions ( )
Stops and removes all actions from the running action list .
stopAction
(
-
action
)
- action
Stops and removes an action from the running action list.
name | type | description |
---|---|---|
action
|
cc.Action |
An action object to be removed. |
stopActionByTag
(
-
tag
)
- tag
Removes an action from the running action list by its tag.
name | type | description |
---|---|---|
tag
|
Number |
A tag that indicates the action to be removed. |
getActionByTag
(
-
tag
)
cc.Action
- tag
Returns an action from the running action list by its tag.
name | type | description |
---|---|---|
tag
|
Number |
returns:
The action object with the given tag.
getNumberOfRunningActions ( ) Number
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.
returns:
init ( ) Boolean deprecated
Initializes the instance of cc.Node
returns:
attr
(
-
attrs
)
- attrs
Properties configuration function All properties in attrs will be set to the node, when the setter of the node is available, the property will be set via setter function.
name | type | description |
---|---|---|
attrs
|
Object |
Properties to be set to node |
setGlobalZOrder
(
-
globalZOrder
)
- globalZOrder
Defines the oder in which the nodes are renderer.
Nodes that have a Global Z Order lower, are renderer first.
In case two or more nodes have the same Global Z Order, the oder is not guaranteed.
The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used.
By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes.
Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order.
Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their ancestors.
And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode.
name | type | description |
---|---|---|
globalZOrder
|
Number |
getGlobalZOrder ( ) number
Return the Node's Global Z Order.
returns:
getScale ( ) Number
Returns the scale factor of the node. Assertion will fail when _scaleX != _scaleY.
returns:
setScale
(
-
scale
-
[scaleY
=scale]
)
- scale
- [scaleY =scale]
getPosition ( ) Vec2
Returns a copy of the position (x,y) of the node in cocos2d coordinates. (0,0) is the left-bottom corner.
returns:
setPosition
(
-
newPosOrxValue
-
[yValue
]
)
- newPosOrxValue
- [yValue ]
Changes the position (x,y) of the node in cocos2d coordinates.
The original point (0,0) is at the left-bottom corner of screen.
Usually we use cc.p(x,y) to compose CCPoint object.
and Passing two numbers (x,y) is more efficient than passing CCPoint object.
name | type | description |
---|---|---|
newPosOrxValue
|
Vec2 | Number |
The position (x,y) of the node in coordinates or the X coordinate for position |
yValue
optional
|
Number |
Y coordinate for position |
examples:
---------------------------------
var size = cc.winSize;
node.setPosition(size.width/2, size.height/2);
getAnchorPoint ( ) Vec2
Returns a copy of the anchor point.
Anchor point 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 anchor point is (0.5,0.5), so it starts at the center of the node.
returns:
setAnchorPoint
(
-
point
-
[y
]
)
- point
- [y ]
Sets the anchor point in percent.
anchor point 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 anchor point is (0.5,0.5), so it starts at the center of the node.
getAnchorPointInPoints ( ) Vec2
Returns a copy of the anchor point in absolute pixels.
you can only read it. If you wish to modify it, use setAnchorPoint
returns:
getContentSize
(
-
[ignoreSizeProvider
=false]
)
Size
- [ignoreSizeProvider =false]
Returns a copy 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 by default.
name | type | description | |
---|---|---|---|
ignoreSizeProvider
optional
|
Boolean | false |
true if you need to get the original size of the node |
returns:
setContentSize
(
-
size
-
[height
]
)
- size
- [height ]
Sets 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.
getBoundingBox ( ) Rect
Returns a "local" axis aligned bounding box of the node.
The returned box is relative only to its parent.
returns:
cleanup ( )
Stops all running actions and schedulers
getChildByTag
(
-
aTag
)
Node
- aTag
getChildByName
(
-
name
)
Node
- name
addChild
(
-
child
-
[localZOrder
]
-
[tag
]
)
- child
- [localZOrder ]
- [tag ]
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
removeFromParent
(
-
[cleanup
=true]
)
- [cleanup =true]
Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
If the cleanup parameter is not passed, it will force a cleanup.
If the node orphan, then nothing happens.
name | type | description | |
---|---|---|---|
cleanup
optional
|
Boolean | true |
true if all actions and callbacks on this node should be removed, false otherwise. |
removeChild
(
-
child
-
[cleanup
=true]
)
- child
- [cleanup =true]
If the cleanup parameter is not passed, it will force a cleanup.
"remove" logic MUST only be on this method
If a class wants to extend the 'removeChild' behavior it only needs
to override this method
removeChildByTag
(
-
tag
-
[cleanup
=true]
)
- tag
- [cleanup =true]
Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter.
If the cleanup parameter is not passed, it will force a cleanup.
removeAllChildren
(
-
[cleanup
=true]
)
- [cleanup =true]
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
If the cleanup parameter is not passed, it will force a cleanup.
name | type | description | |
---|---|---|---|
cleanup
optional
|
Boolean | true |
true if all running actions on all children nodes should be cleanup, false otherwise. |
getParentToNodeTransform ( ) AffineTransform
Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
The matrix is in Pixels.
The returned transform is readonly and cannot be changed.
returns:
getNodeToWorldTransform ( ) AffineTransform
Returns the world affine transform matrix. The matrix is in Pixels.
returns:
getWorldToNodeTransform ( ) AffineTransform
Returns the inverse world affine transform matrix. The matrix is in Pixels.
returns:
convertToNodeSpace
(
-
worldPoint
)
Vec2
- worldPoint
convertToWorldSpace
(
-
nodePoint
)
Vec2
- nodePoint
convertToNodeSpaceAR
(
-
worldPoint
)
Vec2
- worldPoint
convertToWorldSpaceAR
(
-
nodePoint
)
Vec2
- nodePoint
convertTouchToNodeSpace
(
-
touch
)
Vec2
- touch
convertTouchToNodeSpaceAR
(
-
touch
)
Vec2
- touch
getNodeToParentTransform ( ) AffineTransform
Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
The matrix is in Pixels.
returns:
getBoundingBoxToWorld ( ) Rect
Returns a "world" axis aligned bounding box of the node.
returns:
getDisplayedOpacity ( ) number
Returns the displayed opacity of Node, the difference between displayed opacity and opacity is that displayed opacity is calculated based on opacity and parent node's opacity when cascade opacity enabled.
returns:
(
-
parentOpacity
)
- parentOpacity
Update displayed opacity
name | type | description |
---|---|---|
parentOpacity
|
Number |
getDisplayedColor ( ) Color
Returns the displayed color of Node, the difference between displayed color and color is that displayed color is calculated based on color and parent node's color when cascade color enabled.
returns:
setOpacityModifyRGB
(
-
opacityValue
)
- opacityValue
Set whether color should be changed with the opacity value, useless in ccsg.Node, but this function is override in some class to have such behavior.
name | type | description |
---|---|---|
opacityValue
|
Boolean |
isOpacityModifyRGB ( ) Boolean
Get whether color should be changed with the opacity value
returns:
setSiblingIndex
(
-
index
)
- index
Set the sibling index of this node.
name | type | description |
---|---|---|
index
|
Number |
isChildOf
(
-
parent
)
Boolean
- parent
getPositionX
(
-
x
)
- x
Sets the x axis position of the node in cocos2d coordinates.
name | type | description |
---|---|---|
x
|
Number |
The new position in x axis |
setPositionX ( ) Number
Returns the x axis position of the node in cocos2d coordinates.
returns:
getPositionY ( ) Number
Returns the y axis position of the node in cocos2d coordinates.
returns:
setPositionY
(
-
y
)
- y
Sets the y axis position of the node in cocos2d coordinates.
name | type | description |
---|---|---|
y
|
Number |
The new position in y axis |
getLocalZOrder ( ) Number
Returns the local Z order of this node.
returns:
setLocalZOrder
(
-
localZOrder
)
- localZOrder
LocalZOrder is the 'key' used to sort the node relative to its siblings.
The Node's parent will sort all its children based ont the LocalZOrder value.
If two nodes have the same LocalZOrder, then the node that was added first to the children's array
will be in front of the other node in the array.
Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order )
And Nodes that have LocalZOder values smaller than 0 are the "left" subtree
While Nodes with LocalZOder greater than 0 are the "right" subtree.
name | type | description |
---|---|---|
localZOrder
|
Number |
isIgnoreAnchorPointForPosition ( ) Boolean
Returns whether the anchor point will be ignored when you position this node.
When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates.
returns:
ignoreAnchorPointForPosition
(
-
newValue
)
- newValue
Sets whether the anchor point will be ignored when you position this node.
When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates.
This is an internal method, only used by CCLayer and CCScene. Don't call it outside framework.
The default value is false, while in CCLayer and CCScene are true
name | type | description |
---|---|---|
newValue
|
Boolean |
true if anchor point will be ignored when you position this node |
isCascadeOpacityEnabled ( ) Boolean
Returns whether node's opacity value affect its child nodes.
returns:
setCascadeOpacityEnabled
(
-
cascadeOpacityEnabled
)
- cascadeOpacityEnabled
Enable or disable cascade opacity, if cascade enabled, child nodes' opacity will be the multiplication of parent opacity and its own opacity.
name | type | description |
---|---|---|
cascadeOpacityEnabled
|
Boolean |
isCascadeColorEnabled ( ) Boolean
Returns whether node's color value affect its child nodes.
returns:
setCascadeColorEnabled
(
-
cascadeColorEnabled
)
- cascadeColorEnabled
Enable or disable cascade color, if cascade enabled, child nodes' opacity will be the cascade value of parent color and its own color.
name | type | description |
---|---|---|
cascadeColorEnabled
|
Boolean |
destroy ( ) Boolean
Destroy this Object, and release all its own references to other objects.
After destroy, this CCObject is not usable any more. You can use cc.isValid(obj) (or obj.isValid if obj is non-nil) to check whether the object is destroyed before accessing it.
returns:
realDestroyInEditor ( )
In fact, Object's "destroy" will not trigger the destruct operation in Firebal Editor. The destruct operation will be executed by Undo system later.
_destruct ( ) private
Clear all references in the instance.
NOTE: this method will not clear the getter or setter functions which defined in the INSTANCE of CCObject. You can override the _destruct method if you need.
_onPreDestroy ( ) private
Called before the object being destroyed.
_serialize
(
-
exporting
)
object
private
- exporting
_deserialize
(
-
data
-
ctx
)
private
- data
- ctx
Init this object from the custom serialized data.
name | type | description |
---|---|---|
data
|
Object |
the serialized json data |
ctx
|
_Deserializer |
Events
position-changed
Unknown
Event Payload:
-
event
cc.Event-
detail
cc.Vec2old position
-
scale-changed
Unknown
Event Payload:
-
event
cc.Event-
detail
cc.Vec2old scale
-
size-changed
Unknown
Event Payload:
-
event
cc.Event-
detail
cc.Sizeold size
-
anchor-changed
Unknown
Event Payload:
-
event
cc.Event-
detail
cc.Vec2old anchor
-
color-changed
Unknown
Event Payload:
-
event
cc.Event-
detail
cc.Colorold color
-