Class cc.Node
Extends
cc.Class.
Defined in: CCNode.js.
Constructor Attributes | Constructor Name and Description |
---|---|
cc.Node()
cc.Node is the main element. |
Field Attributes | Field Name and Description |
---|---|
<static> <constant> |
cc.Node.StateCallbackType
cc.Node's state callback type
|
Method Attributes | Method Name and Description |
---|---|
addChild(child, zOrder, tag)
"add" logic MUST only be on this method If a class want's to extend the 'addChild' behaviour it only needs |
|
cleanup()
Stops all running actions and schedulers
|
|
convertToNodeSpace(worldPoint)
Converts a Point to node (local) space coordinates.
|
|
convertToNodeSpaceAR(worldPoint)
Converts a Point to node (local) space coordinates.
|
|
convertTouchToNodeSpace(touch)
convenience methods which take a cc.Touch instead of cc.Point
|
|
convertTouchToNodeSpaceAR(touch)
converts a cc.Touch (world coordinates) into a local coordiante.
|
|
convertToWorldSpace(nodePoint)
Converts a Point to world space coordinates.
|
|
convertToWorldSpaceAR(nodePoint)
Converts a local Point to world space coordinates.The result is in Points.
|
|
<static> |
cc.Node.create()
allocates and initializes a node.
|
ctor()
Constructor
|
|
Node description
|
|
draw(ctx)
Override this method to draw your own node. |
|
getActionByTag(tag)
Gets an action from the running action list given its tag
|
|
cc.ActionManager used by all the actions. |
|
anchorPoint is the point around which all transformations and positioning manipulations take place. |
|
AnchorPointInPoints getter
|
|
returns a "local" axis aligned bounding box of the node.
|
|
returns a "world" axis aligned bounding box of the node.
|
|
camera getter: lazy alloc
|
|
getChildByTag(aTag)
Gets a child from the container given its tag
|
|
children getter
|
|
Get children count
|
|
The untransformed size of the node. |
|
GL server side state getter
|
|
getGrid()
grid getter
|
|
used internally for zOrder sorting, don't change this manually
|
|
parent getter
|
|
get/set Position for Lua (pass number faster than cc.Point object) lua code: |
|
rotation getter
|
|
getScale()
Get the scale factor of the node.
|
|
scaleX getter
|
|
scaleY getter
|
|
cc.Scheduler used to schedule all "updates" and timers. |
|
Shader Program getter
|
|
getSkewX()
get the skew degrees in X
|
|
getSkewY()
get the skew degrees in Y
|
|
getTag()
tag getter
|
|
Similar to userData, but instead of holding a void* it holds an id
|
|
ertexZ getter
|
|
zOrder getter
|
|
ignoreAnchorPointForPosition(newValue)
ignoreAnchorPointForPosition setter
|
|
init()
|
|
ignoreAnchorPointForPosition getter
|
|
isRunning getter
|
|
isVisible getter
|
|
Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
|
|
Retrusn the world affine transform matrix.
|
|
Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
|
|
onEnter()
callback that is called every time the cc.Node enters the 'stage'.
|
|
callback that is called when the cc.Node enters in the 'stage'. |
|
onExit()
callback that is called every time the cc.Node leaves the 'stage'.
|
|
callback that is called every time the cc.Node leaves the 'stage'. |
|
Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
|
|
pauses all scheduled selectors and actions.
|
|
release()
|
|
removeAllChildren(cleanup)
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
|
|
removeAllChildrenWithCleanup(cleanup)
|
|
removeChild(child, cleanup)
Removes a child from the container. |
|
removeChildByTag(tag, cleanup)
Removes a child from the container by tag value.
|
|
removeFromParent(cleanup)
Remove itself from its parent node.
|
|
removeFromParentAndCleanup(cleanup)
XXX deprecated
|
|
reorderChild(child, zOrder)
Reorders a child according to a new z value.
|
|
resumes all scheduled callback functions and actions.
|
|
retain()
Currently JavaScript Bindigns (JSB), in some cases, needs to use retain and release.
|
|
runAction(action)
Executes an action, and returns the action that is executed.
|
|
schedule(callback_fn, interval, repeat, delay)
schedules a callback function with interval, repeat and delay.
|
|
scheduleOnce(callback_fn, delay)
Schedules a callback function that runs only once, with a delay of 0 or larger
|
|
schedules the "update" method.
|
|
scheduleUpdateWithPriority(priority)
schedules the "update" callback function with a custom priority.
|
|
setActionManager(actionManager)
cc.ActionManager used by all the actions. |
|
setAnchorPoint(point)
|
|
setContentSize(size)
|
|
setGLServerState(Var)
GL server side state setter
|
|
setGrid(grid)
grid setter
|
|
set the dirty node
|
|
setOrderOfArrival(Var)
used internally for zOrder sorting, don't change this manually
|
|
setParent(Var)
parent setter
|
|
setPosition(newPosOrxValue, yValue)
position setter
|
|
setPositionX(x)
|
|
setPositionY(y)
|
|
setRotation(newRotation)
rotation setter
|
|
setScale(scale, scaleY)
The scale factor of the node.
|
|
setScaleX(newScaleX)
scaleX setter
|
|
setScaleY(newScaleY)
scaleY setter
|
|
setScheduler(scheduler)
cc.Scheduler used to schedule all "updates" and timers. |
|
setShaderProgram(newValue)
Shader Program setter
|
|
setSkewX(newSkewX)
set the skew degrees in X
|
|
setSkewY(newSkewY)
set the skew degrees in Y
|
|
setTag(Var)
tag setter
|
|
setUserData(Var)
|
|
setUserObject(newValue)
Similar to userData, but instead of holding a void* it holds an id
|
|
setVertexZ(Var)
vertexZ setter
|
|
setVisible(Var)
isVisible setter
|
|
setZOrder(z)
|
|
performance improvement, Sort the children array once before drawing, instead of every time when a child is added or reordered |
|
stopAction(action)
Removes an action from the running action list
|
|
stopActionByTag(tag)
Removes an action from the running action list given its tag
|
|
Removes all actions from the running action list
|
|
transform(ctx)
transformations
performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. |
|
performs OpenGL view-matrix transformation of it's ancestors.
|
|
unschedule(callback_fn)
unschedules a custom callback function.
|
|
unschedule all scheduled callback functions: custom callback functions, and the 'update' callback function.
|
|
unschedules the "update" method.
|
|
update(dt)
implement cc.Object's method (override me)
|
|
visit(ctx)
recursive method that visit its children and draw them
|
|
Returns the inverse world affine transform matrix.
|
cc.Node is the main element. Anything thats gets drawn or contains things that get drawn is a cc.Node.
The most popular cc.Nodes are: cc.Scene, cc.Layer, cc.Sprite, cc.Menu.
The main features of a cc.Node are:
- They can contain other cc.Node nodes (addChild, getChildByTag, removeChild, etc)
- They can schedule periodic callback (schedule, unschedule, etc)
- They can execute actions (runAction, stopAction, etc)
Some cc.Node nodes provide extra functionality for them or their children.
Subclassing a cc.Node 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 cc.Node:
- position
- scale (x, y)
- rotation (in degrees, clockwise)
- cc.Camera (an interface to gluLookAt )
- cc.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 cc.Node is a "void" object. It doesn't have a texture
Order in transformations with grid disabled
-# The node will be translated (position)
-# The node will be rotated (rotation)
-# The node will be scaled (scale)
-# The node will be moved according to the camera values (camera)
Order in transformations with grid enabled
-# The node will be translated (position)
-# The node will be rotated (rotation)
-# The node will be scaled (scale)
-# The grid will capture the screen
-# The node will be moved according to the camera values (camera)
-# The grid will render the captured screen
Camera:
- Each node has a camera. By default it points to the center of the cc.Node.
// example cc.Sprite = cc.Node.extend({}); cc.Sprite.initWithImage = function(){ };
"add" logic MUST only be on this method
If a class want's to extend the 'addChild' behaviour it only needs
to override this method
- Parameters:
- {cc.Node} child
- {Number} zOrder
- {Number} tag
- Parameters:
- {cc.Point} worldPoint
- Returns:
- {cc.Point}
treating the returned/received node point as anchor relative.
- Parameters:
- {cc.Point} worldPoint
- Returns:
- {cc.Point}
- Parameters:
- {cc.Touch} touch
- Returns:
- {cc.Point}
- Parameters:
- {cc.Touch} touch
- Returns:
- {cc.Point}
- Parameters:
- {cc.Point} nodePoint
- Returns:
- {cc.Point}
treating the returned/received node point as anchor relative.
- Parameters:
- {cc.Point} nodePoint
- Returns:
- {cc.Point}
// example var node = cc.Node.create();
- Returns:
- {cc.Node}
- Returns:
- {String}
Override this method to draw your own node.
The following GL states will be enabled by default:
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE
But if you enable any other GL state, you should disable it after drawing your node.
- Parameters:
- {CanvasContext} ctx
- Parameters:
- {Number} tag
- Returns:
- {cc.Action}
cc.ActionManager used by all the actions.
(IMPORTANT: If you set a new cc.ActionManager, then previously created actions are going to be removed.)
- Returns:
- {cc.ActionManager}
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.
- Returns:
- {cc.Point}
The returned box is relative only to its parent.
- Returns:
- {cc.Rect}
- Returns:
- {cc.Rect}
- Returns:
- {cc.Camera}
- Parameters:
- {Number} aTag
- Returns:
- {cc.Node}
- Returns:
- {object}
- Returns:
- {Number}
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.
- Returns:
- {cc.Size}
- Returns:
- {Number}
- Returns:
- {cc.GridBase}
- Returns:
- {Number}
- Returns:
- {cc.Node}
get/set Position for Lua (pass number faster than cc.Point object)
lua code:
local x, y = node:getPosition() -- return x, y values from C++
local x = node:getPositionX()
local y = node:getPositionY()
node:setPosition(x, y) -- pass x, y values to C++
node:setPositionX(x)
node:setPositionY(y)
node:setPositionInPixels(x, y) -- pass x, y values to C++
- Returns:
- {cc.Point}
- Returns:
- {Number}
- Returns:
- {Number}
- Returns:
- {Number}
- Returns:
- {Number}
- Returns:
- {Number}
- Returns:
- {Number}
cc.Scheduler used to schedule all "updates" and timers.
IMPORTANT: If you set a new cc.Scheduler, then previously created timers/update are going to be removed.
- Returns:
- {cc.Scheduler}
- Returns:
- {object}
- Returns:
- {Number}
- Returns:
- {Number}
- Returns:
- {Number}
- Returns:
- {object}
- Returns:
- {object}
- Returns:
- {Number}
- Returns:
- {Number}
- Parameters:
- {Boolean} newValue
- Returns:
- {Boolean}
- Returns:
- {Boolean}
- Returns:
- {Boolean}
The matrix is in Pixels.
- Returns:
- {cc.AffineTransform}
- Returns:
- {cc.AffineTransform}
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:
- {Number}
If the cc.Node enters the 'stage' with a transition, this callback is called when the transition starts. During onEnter you can't a "sister/brother" node.
callback that is called when the cc.Node enters in the 'stage'.
If the cc.Node enters the 'stage' with a transition, this callback is called when the transition finishes.
If the cc.Node leaves the 'stage' with a transition, this callback is called when the transition finishes.
During onExit you can't access a sibling node.
callback that is called every time the cc.Node leaves the 'stage'.
If the cc.Node leaves the 'stage' with a transition, this callback is called when the transition starts.
The matrix is in Pixels.
- Returns:
- {Number}
Called internally by onExit
- Parameters:
- {Boolean} cleanup
- Parameters:
- cleanup
Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
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
- Parameters:
- {cc.Node} child
- {Boolean} cleanup
- Parameters:
- {Number} tag
- {Boolean} cleanup
If the cleanup parameter is not passed, it will force a cleanup.
If the node orphan, then nothing happens.
- Parameters:
- {Boolean} cleanup
- Parameters:
- cleanup
The child MUST be already added.
- Parameters:
- {cc.Node} child
- {Number} zOrder
Called internally by onEnter
The node becomes the action's target.
- Parameters:
- {cc.Action} action
- Returns:
- {cc.Action}
- Parameters:
- {function} callback_fn
- {Number} interval
- repeat
- delay
- Parameters:
- {cc.Class} callback_fn
- {Number} delay
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.
Scheduled callback functions with a lower priority will be called before the ones that have a higher value.
Only one "update" callback function could be scheduled per node (You can't have 2 'update' callback functions).
- Parameters:
- {Number} priority
cc.ActionManager used by all the actions.
(IMPORTANT: If you set a new cc.ActionManager, then previously created actions are going to be removed.)
- Parameters:
- {cc.ActionManager} actionManager
- Parameters:
- {cc.Point} point
- Parameters:
- {cc.Size} size
- Parameters:
- {Number} Var
- Parameters:
- {cc.GridBase} grid
- Parameters:
- {Number} Var
- Parameters:
- {cc.Node} Var
- Parameters:
- {cc.Point|Number} newPosOrxValue
- {Number} yValue
- Parameters:
- {Number} x
- Parameters:
- {Number} y
- Parameters:
- {Number} newRotation
- Parameters:
- {Number} scale
- or scaleX value
- {Number} scaleY
- Parameters:
- {Number} newScaleX
- Parameters:
- {Number} newScaleY
cc.Scheduler used to schedule all "updates" and timers.
IMPORTANT: If you set a new cc.Scheduler, then previously created timers/update are going to be removed.
- Parameters:
- scheduler
- Parameters:
- {object} newValue
- Parameters:
- {Number} newSkewX
- Parameters:
- {Number} newSkewY
- Parameters:
- {Number} Var
- Parameters:
- {object} Var
- Parameters:
- {object} newValue
- Parameters:
- {Number} Var
- Parameters:
- {Boolean} Var
- Parameters:
- z
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
- Parameters:
- {cc.Action} action
- Parameters:
- {Number} tag
performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes.
- Parameters:
- {CanvasContext} ctx
Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO)
it's necessary to transform the ancestors again.
- Parameters:
- {function} callback_fn
Actions are not affected by this method.
- Parameters:
- {Number} dt
- Parameters:
- {CanvasContext} ctx
- Returns:
- {cc.AffineTransform}