-
Notifications
You must be signed in to change notification settings - Fork 9
Nodes
Nodes are the core engine entities. Nodes can:
- Be drawn on the screen.
- Contain other nodes.
- Have hierarchical transformations (from parent to children).
- Get input routed.
- Schedule actions and/or tasks.
The core node is cc.node.Node
. Unlike as in V3 API, a Node object by default can draw itself as a solid color. Nodes receive a RenderingContext object as draw
method parameter which allows for arbitrary rendering like stroking, pattern, images, tinting, etc. See (RenderingContext)[RenderingContext] for more information.
It is expected the developer will overwrite draw( ctx )
method instead of subclassing to create a new Node type.
Nodes by default have no input enabled. Mouse/touch events won't be routed to a node unless the method enabledEvents
is called, regardless the developer has registered any touch/mouse callback function. See (Input)[Input] for more info.
Nodes have identification capabilities. You can setTag
a node, or setName
. Since nodes can contain other nodes, the method enumerateChildren(pattern)
matches to node names and invokes a callback for node name match. The enumeration can be recursive and have a directory like structure.
A Node can schedule an undefined amount of Action objects as well as tasks on itself. Actions and tasks will be applied in a timely manner.
Visually, nodes can have three different attributes:
- Color. Which tints images and solid colors.
setColor()
- Alpha. Which modifies node's transparency. Transparency can be cascaded, meaning the transparency can propagate down the node's hierarchy.
setAlpha()
orsetOpacity
. - Alpha blend. Which modifies blending parameters (affects how colos compose when mixed).
setBlendFunc( src, dst)
orsetCompositeOperation( cc.render.CompositeOperation )
.
Finally, nodes can have a transformation applied. For example, they can be rotated, scaled and/or translated. Other types of nodes (like sprites) can be for example flipped. The V4 implementation offers two different transformation anchors:
- position anchor, which affects how nodes are placed on the screen.
- transformation anchor, which affects how nodes are rotated and/or scaled.
These transformations apply hierarchically. For example a node translated will affect all its children position.
Methods like
rotate(r)
,scale(x,y)
,x
,y
,rotation
,scaleX
,scaleY
, etc. will affect a lazily calculated local and global transformation matrices.