Class Index | File Index

Classes


Class cc.Node


Extends cc.Class.

Defined in: CCNode.js.

Class Summary
Constructor Attributes Constructor Name and Description
 

cc.Node is the main element.

Field Summary
Field Attributes Field Name and Description
<static> <constant>  
cc.Node's state callback type
Method Summary
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
to override this method

 
Stops all running actions and schedulers
 
convertToNodeSpace(worldPoint)
Converts a Point to node (local) space coordinates.
 
Converts a Point to node (local) space coordinates.
 
convenience methods which take a cc.Touch instead of cc.Point
 
converts a cc.Touch (world coordinates) into a local coordiante.
 
Converts a Point to world space coordinates.
 
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.

 
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
 
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
 
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:
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++

 
 
 
rotation getter
 
Get the scale factor of the node.
 
scaleX getter
 
scaleY getter
 

cc.Scheduler used to schedule all "updates" and timers.

 
Shader Program getter
 
get the skew degrees in X
 
get the skew degrees in Y
 
tag getter
 
 
Similar to userData, but instead of holding a void* it holds an id
 
ertexZ getter
 
zOrder getter
 
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).
 
callback that is called every time the cc.Node enters the 'stage'.
 

callback that is called when the cc.Node enters in the 'stage'.

 
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.
 
 
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
 
 
removeChild(child, cleanup)

Removes a child from the container.

 
removeChildByTag(tag, cleanup)
Removes a child from the container by tag value.
 
Remove itself from its parent node.
 
XXX deprecated
 
reorderChild(child, zOrder)
Reorders a child according to a new z value.
 
resumes all scheduled callback functions and actions.
 
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.
 
schedules the "update" callback function with a custom priority.
 
setActionManager(actionManager)

cc.ActionManager used by all the actions.

 
 
 
GL server side state setter
 
setGrid(grid)
grid setter
 
set the dirty node
 
used internally for zOrder sorting, don't change this manually
 
setParent(Var)
parent setter
 
setPosition(newPosOrxValue, yValue)
position setter
 
 
 
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
 
 
setUserObject(newValue)
Similar to userData, but instead of holding a void* it holds an id
 
vertexZ setter
 
isVisible setter
 
 

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

 
stopAction(action)
Removes an action from the running action list
 
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.
Class Detail
cc.Node()

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(){
};
Field Detail
<static> <constant> {Number} cc.Node.StateCallbackType
cc.Node's state callback type
Method Detail
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
to override this method

Parameters:
{cc.Node} child
{Number} zOrder
{Number} tag

cleanup()
Stops all running actions and schedulers

{cc.Point} convertToNodeSpace(worldPoint)
Converts a Point to node (local) space coordinates. The result is in Points.
Parameters:
{cc.Point} worldPoint
Returns:
{cc.Point}

{cc.Point} convertToNodeSpaceAR(worldPoint)
Converts a Point to node (local) space coordinates. The result is in Points.
treating the returned/received node point as anchor relative.
Parameters:
{cc.Point} worldPoint
Returns:
{cc.Point}

{cc.Point} convertTouchToNodeSpace(touch)
convenience methods which take a cc.Touch instead of cc.Point
Parameters:
{cc.Touch} touch
Returns:
{cc.Point}

{cc.Point} convertTouchToNodeSpaceAR(touch)
converts a cc.Touch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
Parameters:
{cc.Touch} touch
Returns:
{cc.Point}

{cc.Point} convertToWorldSpace(nodePoint)
Converts a Point to world space coordinates. The result is in Points.
Parameters:
{cc.Point} nodePoint
Returns:
{cc.Point}

{cc.Point} convertToWorldSpaceAR(nodePoint)
Converts a local Point to world space coordinates.The result is in Points.
treating the returned/received node point as anchor relative.
Parameters:
{cc.Point} nodePoint
Returns:
{cc.Point}

<static> {cc.Node} cc.Node.create()
allocates and initializes a node.
// example
var node = cc.Node.create();
Returns:
{cc.Node}

ctor()
Constructor

{String} description()
Node description
Returns:
{String}

draw(ctx)

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

{cc.Action} getActionByTag(tag)
Gets an action from the running action list given its tag
Parameters:
{Number} tag
Returns:
{cc.Action}

{cc.ActionManager} getActionManager()

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}

getAnchorPoint()

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.


{cc.Point} getAnchorPointInPoints()
AnchorPointInPoints getter
Returns:
{cc.Point}

{cc.Rect} getBoundingBox()
returns a "local" axis aligned bounding box of the node.
The returned box is relative only to its parent.
Returns:
{cc.Rect}

{cc.Rect} getBoundingBoxToWorld()
returns a "world" axis aligned bounding box of the node.
Returns:
{cc.Rect}

{cc.Camera} getCamera()
camera getter: lazy alloc
Returns:
{cc.Camera}

{cc.Node} getChildByTag(aTag)
Gets a child from the container given its tag
Parameters:
{Number} aTag
Returns:
{cc.Node}

{object} getChildren()
children getter
Returns:
{object}

{Number} getChildrenCount()
Get children count
Returns:
{Number}

{cc.Size} getContentSize()

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}

{Number} getGLServerState()
GL server side state getter
Returns:
{Number}

{cc.GridBase} getGrid()
grid getter
Returns:
{cc.GridBase}

{Number} getOrderOfArrival()
used internally for zOrder sorting, don't change this manually
Returns:
{Number}

{cc.Node} getParent()
parent getter
Returns:
{cc.Node}

{cc.Point} getPosition()

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}

{Number} getPositionX()
Returns:
{Number}

{Number} getPositionY()
Returns:
{Number}

{Number} getRotation()
rotation getter
Returns:
{Number}

{Number} getScale()
Get the scale factor of the node.
Returns:
{Number}

{Number} getScaleX()
scaleX getter
Returns:
{Number}

{Number} getScaleY()
scaleY getter
Returns:
{Number}

{cc.Scheduler} getScheduler()

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}

{object} getShaderProgram()
Shader Program getter
Returns:
{object}

{Number} getSkewX()
get the skew degrees in X
Returns:
{Number}

{Number} getSkewY()
get the skew degrees in Y
Returns:
{Number}

{Number} getTag()
tag getter
Returns:
{Number}

{object} getUserData()
Returns:
{object}

{object} getUserObject()
Similar to userData, but instead of holding a void* it holds an id
Returns:
{object}

{Number} getVertexZ()
ertexZ getter
Returns:
{Number}

{Number} getZOrder()
zOrder getter
Returns:
{Number}

ignoreAnchorPointForPosition(newValue)
ignoreAnchorPointForPosition setter
Parameters:
{Boolean} newValue

init()

{Boolean} isIgnoreAnchorPointForPosition()
ignoreAnchorPointForPosition getter
Returns:
{Boolean}

{Boolean} isRunning()
isRunning getter
Returns:
{Boolean}

{Boolean} isVisible()
isVisible getter
Returns:
{Boolean}

{cc.AffineTransform} nodeToParentTransform()
Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
The matrix is in Pixels.
Returns:
{cc.AffineTransform}

{cc.AffineTransform} nodeToWorldTransform()
Retrusn the world affine transform matrix. The matrix is in Pixels.
Returns:
{cc.AffineTransform}

{Number} 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.
Returns:
{Number}

onEnter()
callback that is called every time the cc.Node enters the 'stage'.
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.

onEnterTransitionDidFinish()

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.


onExit()
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 finishes.
During onExit you can't access a sibling node.

onExitTransitionDidStart()

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.


{Number} parentToNodeTransform()
Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
The matrix is in Pixels.
Returns:
{Number}

pauseSchedulerAndActions()
pauses all scheduled selectors and actions.
Called internally by onExit

release()

removeAllChildren(cleanup)
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.
Parameters:
{Boolean} cleanup

removeAllChildrenWithCleanup(cleanup)
Parameters:
cleanup

removeChild(child, 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

removeChildByTag(tag, cleanup)
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.
Parameters:
{Number} tag
{Boolean} cleanup

removeFromParent(cleanup)
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.
Parameters:
{Boolean} cleanup

removeFromParentAndCleanup(cleanup)
XXX deprecated
Parameters:
cleanup

reorderChild(child, zOrder)
Reorders a child according to a new z value.
The child MUST be already added.
Parameters:
{cc.Node} child
{Number} zOrder

resumeSchedulerAndActions()
resumes all scheduled callback functions and actions.
Called internally by onEnter

retain()
Currently JavaScript Bindigns (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug

{cc.Action} runAction(action)
Executes an action, and returns the action that is executed.
The node becomes the action's target.
Parameters:
{cc.Action} action
Returns:
{cc.Action}

schedule(callback_fn, interval, repeat, delay)
schedules a callback function with interval, repeat and delay.
Parameters:
{function} callback_fn
{Number} interval
repeat
delay

scheduleOnce(callback_fn, delay)
Schedules a callback function that runs only once, with a delay of 0 or larger
Parameters:
{cc.Class} callback_fn
{Number} delay

scheduleUpdate()
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.

scheduleUpdateWithPriority(priority)
schedules the "update" callback function with a custom priority. This callback function will be called every frame.
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

setActionManager(actionManager)

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

setAnchorPoint(point)
Parameters:
{cc.Point} point

setContentSize(size)
Parameters:
{cc.Size} size

setGLServerState(Var)
GL server side state setter
Parameters:
{Number} Var

setGrid(grid)
grid setter
Parameters:
{cc.GridBase} grid

setNodeDirty()
set the dirty node

setOrderOfArrival(Var)
used internally for zOrder sorting, don't change this manually
Parameters:
{Number} Var

setParent(Var)
parent setter
Parameters:
{cc.Node} Var

setPosition(newPosOrxValue, yValue)
position setter
Parameters:
{cc.Point|Number} newPosOrxValue
{Number} yValue

setPositionX(x)
Parameters:
{Number} x

setPositionY(y)
Parameters:
{Number} y

setRotation(newRotation)
rotation setter
Parameters:
{Number} newRotation

setScale(scale, scaleY)
The scale factor of the node. 1.0 is the default scale factor.
Parameters:
{Number} scale
or scaleX value
{Number} scaleY

setScaleX(newScaleX)
scaleX setter
Parameters:
{Number} newScaleX

setScaleY(newScaleY)
scaleY setter
Parameters:
{Number} newScaleY

setScheduler(scheduler)

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

setShaderProgram(newValue)
Shader Program setter
Parameters:
{object} newValue

setSkewX(newSkewX)
set the skew degrees in X
Parameters:
{Number} newSkewX

setSkewY(newSkewY)
set the skew degrees in Y
Parameters:
{Number} newSkewY

setTag(Var)
tag setter
Parameters:
{Number} Var

setUserData(Var)
Parameters:
{object} Var

setUserObject(newValue)
Similar to userData, but instead of holding a void* it holds an id
Parameters:
{object} newValue

setVertexZ(Var)
vertexZ setter
Parameters:
{Number} Var

setVisible(Var)
isVisible setter
Parameters:
{Boolean} Var

setZOrder(z)
Parameters:
z

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


stopAction(action)
Removes an action from the running action list
Parameters:
{cc.Action} action

stopActionByTag(tag)
Removes an action from the running action list given its tag
Parameters:
{Number} tag

stopAllActions()
Removes all actions from the running action list

transform(ctx)
transformations
performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes.
Parameters:
{CanvasContext} ctx

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.

unschedule(callback_fn)
unschedules a custom callback function.
Parameters:
{function} callback_fn

unscheduleAllCallbacks()
unschedule all scheduled callback functions: custom callback functions, and the 'update' callback function.
Actions are not affected by this method.

unscheduleUpdate()
unschedules the "update" method.

update(dt)
implement cc.Object's method (override me)
Parameters:
{Number} dt

updateTransform()

visit(ctx)
recursive method that visit its children and draw them
Parameters:
{CanvasContext} ctx

{cc.AffineTransform} worldToNodeTransform()
Returns the inverse world affine transform matrix. The matrix is in Pixels.
Returns:
{cc.AffineTransform}

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Jan 09 2013 07:51:52 GMT-0800 (PST)