abitofcode

Demystifying CCNode

I’m working on a CCNode explanation that I hope will clear up a lot of the confusion that pops up in the forum on a regular basis. In the meantime the following comes directly from the CCNode.m file;

/** CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
 The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.
 
 The main features of a CCNode are:
 - They can contain other CCNode nodes (addChild, getChildByTag, removeChild, etc)
 - They can schedule periodic callback (schedule, unschedule, etc)
 - They can execute actions (runAction, stopAction, etc)
 
 Some CCNode nodes provide extra functionality for them or their children.
 
 Subclassing a CCNode 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 CCNode:
 - position
 - scale (x, y)
 - rotation (in degrees, clockwise)
 - CCCamera (an interface to gluLookAt )
 - CCGridBase (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 CCNode 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 skewed (skewX, skewY)
 -# The node will be scaled (scale, scaleX, scaleY)
 -# 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 skewed (skewX, skewY)
 -# The node will be scaled (scale, scaleX, scaleY)
 -# 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 CCNode.
 */

Some points to note;

* they can contain other CCNode nodes (addChild, getChildByTag, removeChild, etc)
* A CCNode is a “void” object. It doesn’t have a texture and so…
* has a default contentSize: (x=0,y=0) (CCSprites set their initial contentSize from the size of the supplied texture)
* has a default anchorPoint: (x=0,y=0) (0.5f,0.5f makes no sense when the node has no size)
* Each node has a camera. By default it points to the center of the CCNode.

2 Comments

  1. A concise summary. I wasn’t aware of the order of transformations, so thanks!

    How’s life as a UK indie?

  2. Thanks Chris! This kind of information is really good. I had no idea that each CCNode had a camera…hmmm…

%d bloggers like this: