2010-11-12 17:26:01 +08:00
/****************************************************************************
2012-06-14 15:13:16 +08:00
Copyright ( c ) 2010 - 2012 cocos2d - x . org
2012-02-02 10:39:19 +08:00
Copyright ( c ) 2008 - 2010 Ricardo Quesada
Copyright ( c ) 2009 Valentin Milea
Copyright ( c ) 2011 Zynga Inc .
2012-02-02 15:58:10 +08:00
2012-02-02 10:39:19 +08:00
http : //www.cocos2d-x.org
2012-02-02 15:58:10 +08:00
2012-02-02 10:39:19 +08:00
Permission is hereby granted , free of charge , to any person obtaining a copy
of this software and associated documentation files ( the " Software " ) , to deal
in the Software without restriction , including without limitation the rights
to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
copies of the Software , and to permit persons to whom the Software is
furnished to do so , subject to the following conditions :
2012-02-02 15:58:10 +08:00
2012-02-02 10:39:19 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software .
2012-02-02 15:58:10 +08:00
2012-02-02 10:39:19 +08:00
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-07 15:15:30 +08:00
2012-09-17 15:02:24 +08:00
# ifndef __PLATFORM_CCNODE_H__
# define __PLATFORM_CCNODE_H__
2010-07-08 10:25:52 +08:00
2010-07-14 11:18:05 +08:00
# include "ccMacros.h"
2012-06-19 13:50:11 +08:00
# include "cocoa/CCAffineTransform.h"
# include "cocoa/CCArray.h"
2010-12-24 15:04:26 +08:00
# include "CCGL.h"
2012-06-19 13:50:11 +08:00
# include "shaders/ccGLStateCache.h"
# include "shaders/CCGLProgram.h"
2012-03-14 14:55:17 +08:00
# include "kazmath/kazmath.h"
2012-08-31 21:23:23 +08:00
# include "script_support/CCScriptSupport.h"
2010-07-07 15:15:30 +08:00
2012-03-23 17:31:28 +08:00
NS_CC_BEGIN
class CCCamera ;
class CCGridBase ;
class CCPoint ;
class CCTouch ;
class CCAction ;
class CCRGBAProtocol ;
2012-04-19 14:35:52 +08:00
class CCLabelProtocol ;
class CCScheduler ;
2012-03-23 17:31:28 +08:00
class CCActionManager ;
2012-06-20 18:09:11 +08:00
/**
* @ addtogroup base_nodes
* @ {
*/
2012-03-23 17:31:28 +08:00
enum {
2012-04-19 14:35:52 +08:00
kCCNodeTagInvalid = - 1 ,
2012-03-23 17:31:28 +08:00
} ;
enum {
kCCNodeOnEnter ,
2012-08-27 14:03:42 +08:00
kCCNodeOnExit ,
2012-08-28 09:08:27 +08:00
kCCNodeOnEnterTransitionDidFinish ,
2012-10-23 01:48:22 +08:00
kCCNodeOnExitTransitionDidStart ,
kCCNodeOnCleanup
2012-03-23 17:31:28 +08:00
} ;
2012-09-17 15:02:24 +08:00
/** @brief CCNode is the main element. Anything that gets drawn or contains things that get drawn is a CCNode.
2012-03-23 17:31:28 +08:00
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 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 CCNode .
*/
class CC_DLL CCNode : public CCObject
{
2012-11-14 18:05:15 +08:00
protected :
// rotation angle
float m_fRotationX , m_fRotationY ;
// scaling factors
float m_fScaleX , m_fScaleY ;
// openGL real Z vertex
float m_fVertexZ ;
// position of the node
CCPoint m_obPosition ;
// skew angles
float m_fSkewX , m_fSkewY ;
// anchor point in points
CCPoint m_obAnchorPointInPoints ;
// anchor point normalized (NOT in points)
CCPoint m_obAnchorPoint ;
// untransformed size of the node
CCSize m_obContentSize ;
// transform
CCAffineTransform m_sTransform , m_sInverse ;
// a Camera
CCCamera * m_pCamera ;
// a Grid
CCGridBase * m_pGrid ;
// z-order value
int m_nZOrder ;
// array of children
CCArray * m_pChildren ;
// weak ref to parent
CCNode * m_pParent ;
// a tag. any number you want to assign to the node
int m_nTag ;
// user data field
void * m_pUserData ;
CCObject * m_pUserObject ;
// Shader
CCGLProgram * m_pShaderProgram ;
// Server side state
ccGLServerState m_eGLServerState ;
// used to preserve sequence while sorting children with the same zOrder
unsigned int m_uOrderOfArrival ;
// scheduler used to schedule timers and updates
CCScheduler * m_pScheduler ;
// ActionManager used to handle all the actions
CCActionManager * m_pActionManager ;
// Is running
bool m_bRunning ;
bool m_bTransformDirty ;
bool m_bInverseDirty ;
// is visible
bool m_bVisible ;
// If true, the Anchor Point will be (0,0) when you position the CCNode.
// Used by CCLayer and CCScene
bool m_bIgnoreAnchorPointForPosition ;
2012-03-23 17:31:28 +08:00
2012-11-14 18:05:15 +08:00
bool m_bReorderChildDirty ;
// Properties for script
// script handler
int m_nScriptHandler ;
// script type, lua or javascript
ccScriptType m_eScriptType ;
2012-03-23 17:31:28 +08:00
2012-11-14 18:05:15 +08:00
public :
// getter & setter
2012-04-19 14:35:52 +08:00
/** The z order of the node relative to it's "brothers": children of the same parent */
2012-11-14 18:05:15 +08:00
virtual int getZOrder ( ) ;
virtual void setZOrder ( int nZOrder ) ;
2012-03-23 17:31:28 +08:00
/** The real openGL Z vertex.
Differences between openGL Z vertex and cocos2d Z order :
- OpenGL Z modifies the Z vertex , and not the Z order in the relation between parent - children
- OpenGL Z might require to set 2 D projection
- cocos2d Z order works OK if all the nodes uses the same openGL Z vertex . eg : vertexZ = 0
@ warning : Use it at your own risk since it might break the cocos2d parent - children z order
@ since v0 .8
*/
2012-11-14 18:05:15 +08:00
virtual float getVertexZ ( ) ;
virtual void setVertexZ ( float fVertexZ ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the X scale factor. */
2012-11-14 18:05:15 +08:00
virtual float getScaleX ( ) ;
virtual void setScaleX ( float fScaleX ) ;
2012-03-23 17:31:28 +08:00
/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the Y scale factor. */
2012-11-14 18:05:15 +08:00
virtual float getScaleY ( ) ;
virtual void setScaleY ( float fScaleY ) ;
2012-03-23 17:31:28 +08:00
/** Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner. */
2012-11-20 16:34:55 +08:00
virtual CCPoint getPosition ( ) ;
2012-11-14 18:05:15 +08:00
virtual void setPosition ( const CCPoint & position ) ;
2012-03-23 17:31:28 +08:00
/** The X skew angle of the node in degrees.
This angle describes the shear distortion in the X direction .
Thus , it is the angle between the Y axis and the left edge of the shape
The default skewX angle is 0. Positive values distort the node in a CW direction .
*/
2012-11-14 18:05:15 +08:00
virtual float getSkewX ( ) ;
virtual void setSkewX ( float fSkewX ) ;
2012-03-23 17:31:28 +08:00
/** The Y skew angle of the node in degrees.
This angle describes the shear distortion in the Y direction .
Thus , it is the angle between the X axis and the bottom edge of the shape
The default skewY angle is 0. Positive values distort the node in a CCW direction .
*/
2012-11-14 18:05:15 +08:00
virtual float getSkewY ( ) ;
virtual void setSkewY ( float fSkewY ) ;
virtual CCArray * getChildren ( ) ;
2012-03-23 17:31:28 +08:00
/** A CCCamera object that lets you move the node using a gluLookAt
*/
2012-11-14 18:05:15 +08:00
virtual CCCamera * getCamera ( ) ;
2012-03-23 17:31:28 +08:00
/** A CCGrid object that is used when applying effects */
2012-11-14 18:05:15 +08:00
virtual CCGridBase * getGrid ( ) ;
virtual void setGrid ( CCGridBase * pGrid ) ;
2012-03-23 17:31:28 +08:00
/** A tag used to identify the node easily */
2012-11-14 18:05:15 +08:00
virtual int getTag ( ) ;
virtual void setTag ( int nTag ) ;
2012-03-23 17:31:28 +08:00
/** A custom user data pointer */
2012-11-14 18:05:15 +08:00
virtual void * getUserData ( ) ;
virtual void setUserData ( void * pUserData ) ;
2012-04-19 14:35:52 +08:00
/** Similar to userData, but instead of holding a void* it holds an id */
2012-11-14 18:05:15 +08:00
virtual CCObject * getUserObject ( ) ;
virtual void setUserObject ( CCObject * pUserObject ) ;
2012-04-19 14:35:52 +08:00
/** Shader Program
@ since v2 .0
*/
2012-11-14 18:05:15 +08:00
virtual CCGLProgram * getShaderProgram ( ) ;
virtual void setShaderProgram ( CCGLProgram * pShaderProgram ) ;
2012-04-19 14:35:52 +08:00
/** used internally for zOrder sorting, don't change this manually */
2012-11-14 18:05:15 +08:00
virtual unsigned int getOrderOfArrival ( ) ;
virtual void setOrderOfArrival ( unsigned int uOrderOfArrival ) ;
2012-04-19 14:35:52 +08:00
/** GL server side state
@ since v2 .0
2012-11-14 18:05:15 +08:00
*/
virtual ccGLServerState getGLServerState ( ) ;
virtual void setGLServerState ( ccGLServerState glServerState ) ;
2012-04-19 14:35:52 +08:00
/** CCActionManager used by all the actions.
IMPORTANT : If you set a new CCActionManager , then previously created actions are going to be removed .
@ since v2 .0
*/
2012-11-14 18:05:15 +08:00
virtual CCActionManager * getActionManager ( ) ;
virtual void setActionManager ( CCActionManager * pActionManager ) ;
2012-04-19 14:35:52 +08:00
/** CCScheduler used to schedule all "updates" and timers.
IMPORTANT : If you set a new CCScheduler , then previously created timers / update are going to be removed .
@ since v2 .0
*/
2012-11-14 18:05:15 +08:00
virtual CCScheduler * getScheduler ( ) ;
virtual void setScheduler ( CCScheduler * pScheduler ) ;
/** A weak reference to the parent */
virtual CCNode * getParent ( ) ;
virtual void setParent ( CCNode * pParent ) ;
/** 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 .
@ since v0 .8
*/
2012-11-20 16:34:55 +08:00
virtual CCPoint getAnchorPoint ( ) ;
2012-11-14 18:05:15 +08:00
virtual void setAnchorPoint ( const CCPoint & anchorPoint ) ;
/** The anchorPoint in absolute pixels.
Since v0 .8 you can only read it . If you wish to modify it , use anchorPoint instead
*/
2012-11-20 16:34:55 +08:00
virtual CCPoint getAnchorPointInPoints ( ) ;
2012-11-14 18:05:15 +08:00
/** 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 .
@ since v0 .8
*/
2012-11-20 16:34:55 +08:00
virtual CCSize getContentSize ( ) ;
2012-11-14 18:05:15 +08:00
virtual void setContentSize ( const CCSize & contentSize ) ;
2012-02-02 15:58:10 +08:00
2012-11-14 18:05:15 +08:00
virtual bool isVisible ( ) ;
virtual void setVisible ( bool visible ) ;
/** Get the scale factor of the node.
@ warning : Assert when m_fScaleX ! = m_fScaleY .
*/
virtual float getScale ( ) ;
/** The scale factor of the node. 1.0 is the default scale factor. It modifies the X and Y scale at the same time. */
virtual void setScale ( float scale ) ;
/** The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. */
virtual float getRotation ( ) ;
virtual void setRotation ( float fRotation ) ;
/** The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. It only modifies the X rotation performing a horizontal rotational skew . */
virtual float getRotationX ( ) ;
virtual void setRotationX ( float fRotaionX ) ;
/** The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. It only modifies the Y rotation performing a vertical rotational skew . */
virtual float getRotationY ( ) ;
virtual void setRotationY ( float fRotationY ) ;
2012-02-02 15:58:10 +08:00
2012-11-14 18:05:15 +08:00
/** whether or not the node is running */
virtual bool isRunning ( ) ;
2012-03-23 17:31:28 +08:00
2012-11-14 18:05:15 +08:00
// If true, the Anchor Point will be (0,0) when you position the CCNode.
// Used by CCLayer and CCScene
virtual bool isIgnoreAnchorPointForPosition ( ) ;
virtual void ignoreAnchorPointForPosition ( bool isIgnoreAnchorPointForPosition ) ;
2012-03-23 17:31:28 +08:00
2012-11-14 18:05:15 +08:00
/** Get children count */
unsigned int getChildrenCount ( void ) ;
2012-04-19 14:35:52 +08:00
2012-11-14 18:05:15 +08:00
inline int getScriptHandler ( ) { return m_nScriptHandler ; } ;
2012-04-19 14:35:52 +08:00
2012-11-14 18:05:15 +08:00
/** get/set Position for Lua (pass number faster than CCPoint object)
lua code :
local pos = node : getPositionLua ( ) - - return CCPoint object from C + +
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 + +
*/
const CCPoint & getPositionLua ( void ) ;
void getPosition ( float * x , float * y ) ;
float getPositionX ( void ) ;
float getPositionY ( void ) ;
void setPositionX ( float x ) ;
void setPositionY ( float y ) ;
void setPosition ( float x , float y ) ;
void _setZOrder ( int z ) ;
2012-03-23 17:31:28 +08:00
public :
2012-04-19 14:35:52 +08:00
CCNode ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
virtual ~ CCNode ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
const char * description ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** allocates and initializes a node.
2012-03-23 17:31:28 +08:00
The node will be created as " autorelease " .
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-03-23 17:31:28 +08:00
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCNode * node ( void ) ;
2012-06-14 15:13:16 +08:00
/** allocates and initializes a node.
The node will be created as " autorelease " .
*/
static CCNode * create ( void ) ;
2012-03-23 17:31:28 +08:00
2012-09-17 15:02:24 +08:00
//scene management
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** callback that is called every time the CCNode enters the 'stage'.
2012-03-23 17:31:28 +08:00
If the CCNode enters the ' stage ' with a transition , this callback is called when the transition starts .
During onEnter you can ' t a " sister/brother " node .
*/
2012-04-19 14:35:52 +08:00
virtual void onEnter ( ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** callback that is called when the CCNode enters in the 'stage'.
2012-03-23 17:31:28 +08:00
If the CCNode enters the ' stage ' with a transition , this callback is called when the transition finishes .
@ since v0 .8
*/
2012-04-19 14:35:52 +08:00
virtual void onEnterTransitionDidFinish ( ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** callback that is called every time the CCNode leaves the 'stage'.
2012-03-23 17:31:28 +08:00
If the CCNode leaves the ' stage ' with a transition , this callback is called when the transition finishes .
During onExit you can ' t access a sibling node .
*/
2012-04-19 14:35:52 +08:00
virtual void onExit ( ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** callback that is called every time the CCNode leaves the 'stage'.
If the CCNode leaves the ' stage ' with a transition , this callback is called when the transition starts .
*/
virtual void onExitTransitionDidStart ( ) ;
2012-03-23 17:31:28 +08:00
/** Register onEnter/onExit handler script function
Script handler auto unregister after onEnter ( ) .
*/
virtual void registerScriptHandler ( int nHandler ) ;
virtual void unregisterScriptHandler ( void ) ;
2012-04-19 14:35:52 +08:00
// composition: ADD
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Adds a child to the container with z-order as 0.
2012-03-23 17:31:28 +08:00
If the child is added to a ' running ' node , then ' onEnter ' and ' onEnterTransitionDidFinish ' will be called immediately .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual void addChild ( CCNode * child ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Adds a child to the container with a z-order
2012-03-23 17:31:28 +08:00
If the child is added to a ' running ' node , then ' onEnter ' and ' onEnterTransitionDidFinish ' will be called immediately .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual void addChild ( CCNode * child , int zOrder ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Adds a child to the container with z order and tag
2012-03-23 17:31:28 +08:00
If the child is added to a ' running ' node , then ' onEnter ' and ' onEnterTransitionDidFinish ' will be called immediately .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual void addChild ( CCNode * child , int zOrder , int tag ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
// composition: REMOVE
2012-03-23 17:31:28 +08:00
2012-11-14 18:05:15 +08:00
/** Remove itself from its parent node forcing a cleanup.
If the node orphan , then nothing happens .
@ since v2 .1
*/
2012-11-05 18:41:52 +08:00
virtual void removeFromParent ( ) ;
2012-04-19 14:35:52 +08:00
/** Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
2012-03-23 17:31:28 +08:00
If the node orphan , then nothing happens .
@ since v0 .99 .3
*/
2012-11-05 18:41:52 +08:00
virtual void removeFromParentAndCleanup ( bool cleanup ) ;
2012-11-14 18:05:15 +08:00
/** Removes a child from the container forcing a cleanup
@ since v2 .1
*/
2012-11-05 18:41:52 +08:00
virtual void removeChild ( CCNode * child ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual void removeChild ( CCNode * child , bool cleanup ) ;
2012-03-23 17:31:28 +08:00
2012-11-14 18:05:15 +08:00
/** Removes a child from the container by tag value forcing a cleanup.
@ since v2 .1
*/
2012-11-05 18:41:52 +08:00
virtual void removeChildByTag ( int tag ) ;
2012-04-19 14:35:52 +08:00
/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-11-05 18:41:52 +08:00
virtual void removeChildByTag ( int tag , bool cleanup ) ;
2012-11-14 18:05:15 +08:00
/** Removes all children from the container forcing a cleanup.
@ since v2 .1
*/
2012-11-05 18:41:52 +08:00
virtual void removeAllChildren ( ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual void removeAllChildrenWithCleanup ( bool cleanup ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
// composition: GET
/** Gets a child from the container given its tag
2012-03-23 17:31:28 +08:00
@ return returns a CCNode object
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCNode * getChildByTag ( int tag ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Reorders a child according to a new z value.
2012-03-23 17:31:28 +08:00
* The child MUST be already added .
*/
2012-04-19 14:35:52 +08:00
virtual void reorderChild ( CCNode * child , int zOrder ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** 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 */
virtual void sortAllChildren ( ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Stops all running actions and schedulers
2012-03-23 17:31:28 +08:00
@ since v0 .8
*/
2012-04-19 14:35:52 +08:00
virtual void cleanup ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
// draw
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Override this method to draw your own node.
2012-03-23 17:31:28 +08:00
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 .
*/
2012-04-19 14:35:52 +08:00
virtual void draw ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** recursive method that visit its children and draw them */
virtual void visit ( void ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
// transformations
2012-11-14 18:05:15 +08:00
// MARMALADE ADDED THIS... SO IT IS NO LONGER SPECIFIC TO CCSprite
/** updates the quad according the the rotation, position, scale values. */
2012-10-30 10:24:28 +08:00
virtual void updateTransform ( void ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. */
void transform ( void ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** performs OpenGL view-matrix transformation of it's ancestors.
2012-03-23 17:31:28 +08:00
Generally the ancestors are already transformed , but in certain cases ( eg : attaching a FBO )
it ' s necessary to transform the ancestors again .
@ since v0 .7 .2
*/
2012-04-19 14:35:52 +08:00
void transformAncestors ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** returns a "local" axis aligned bounding box of the node.
2012-03-23 17:31:28 +08:00
The returned box is relative only to its parent .
@ since v0 .8 .2
*/
2012-04-19 14:35:52 +08:00
CCRect boundingBox ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
// actions
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Executes an action, and returns the action that is executed.
2012-03-23 17:31:28 +08:00
The node becomes the action ' s target .
@ warning Starting from v0 .8 actions don ' t retain their target anymore .
@ since v0 .7 .1
@ return An Action pointer
*/
2012-04-19 14:35:52 +08:00
CCAction * runAction ( CCAction * action ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** Removes all actions from the running action list */
void stopAllActions ( void ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** Removes an action from the running action list */
void stopAction ( CCAction * action ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Removes an action from the running action list given its tag
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
void stopActionByTag ( int tag ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Gets an action from the running action list given its tag
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
@ return the Action the with the given tag
*/
2012-04-19 14:35:52 +08:00
CCAction * getActionByTag ( int tag ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
2012-03-23 17:31:28 +08:00
* 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.
*/
2012-04-19 14:35:52 +08:00
unsigned int numberOfRunningActions ( void ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
// timers
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** check whether a selector is scheduled. */
bool isScheduled ( SEL_SCHEDULE selector ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** schedules the "update" method. It will use the order number 0. This method will be called every frame.
2012-03-23 17:31:28 +08:00
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 .
2012-02-02 15:58:10 +08:00
2012-03-23 17:31:28 +08:00
@ since v0 .99 .3
*/
2012-04-19 14:35:52 +08:00
void scheduleUpdate ( void ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/** schedules the "update" selector with a custom priority. This selector will be called every frame.
2012-03-23 17:31:28 +08:00
Scheduled selectors with a lower priority will be called before the ones that have a higher value .
Only one " update " selector could be scheduled per node ( You can ' t have 2 ' update ' selectors ) .
2012-02-02 15:58:10 +08:00
2012-03-23 17:31:28 +08:00
@ since v0 .99 .3
*/
2012-04-19 14:35:52 +08:00
void scheduleUpdateWithPriority ( int priority ) ;
2012-02-02 15:58:10 +08:00
2012-04-19 14:35:52 +08:00
/* unschedules the "update" method.
2012-02-02 15:58:10 +08:00
2012-03-23 17:31:28 +08:00
@ since v0 .99 .3
*/
2012-04-19 14:35:52 +08:00
void unscheduleUpdate ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** schedules a selector.
2012-03-23 17:31:28 +08:00
The scheduled selector will be ticked every frame
*/
2012-04-19 14:35:52 +08:00
void schedule ( SEL_SCHEDULE selector ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** schedules a custom selector with an interval time in seconds.
2012-03-23 17:31:28 +08:00
If time is 0 it will be ticked every frame .
If time is 0 , it is recommended to use ' scheduleUpdate ' instead .
If the selector is already scheduled , then the interval parameter
will be updated without scheduling it again .
*/
2012-06-08 13:55:28 +08:00
void schedule ( SEL_SCHEDULE selector , float interval ) ;
2012-04-19 14:35:52 +08:00
/**
repeat will execute the action repeat + 1 times , for a continues action use kCCRepeatForever
delay is the amount of time the action will wait before execution
*/
2012-06-08 13:55:28 +08:00
void schedule ( SEL_SCHEDULE selector , float interval , unsigned int repeat , float delay ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/**
Schedules a selector that runs only once , with a delay of 0 or larger
*/
2012-06-08 13:55:28 +08:00
void scheduleOnce ( SEL_SCHEDULE selector , float delay ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** unschedules a custom selector.*/
void unschedule ( SEL_SCHEDULE selector ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** unschedule all scheduled selectors: custom selectors, and the 'update' selector.
2012-03-23 17:31:28 +08:00
Actions are not affected by this method .
@ since v0 .99 .3
*/
2012-04-19 14:35:52 +08:00
void unscheduleAllSelectors ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** resumes all scheduled selectors and actions.
2012-03-23 17:31:28 +08:00
Called internally by onEnter
*/
2012-04-19 14:35:52 +08:00
void resumeSchedulerAndActions ( void ) ;
/** pauses all scheduled selectors and actions.
2012-03-23 17:31:28 +08:00
Called internally by onExit
*/
2012-04-19 14:35:52 +08:00
void pauseSchedulerAndActions ( void ) ;
2012-11-14 18:05:15 +08:00
/* Update will be called automatically every frame if "scheduleUpdate" is called, and the node is "live"
*/
virtual void update ( float fDelta ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
// transformation methods
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
2012-03-23 17:31:28 +08:00
The matrix is in Pixels .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual CCAffineTransform nodeToParentTransform ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
2012-03-23 17:31:28 +08:00
The matrix is in Pixels .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual CCAffineTransform parentToNodeTransform ( void ) ;
2012-03-23 17:31:28 +08:00
2012-09-17 15:02:24 +08:00
/** Returns the world affine transform matrix. The matrix is in Pixels.
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual CCAffineTransform nodeToWorldTransform ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Returns the inverse world affine transform matrix. The matrix is in Pixels.
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
virtual CCAffineTransform worldToNodeTransform ( void ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** Converts a Point to node (local) space coordinates. The result is in Points.
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCPoint convertToNodeSpace ( const CCPoint & worldPoint ) ;
/** Converts a Point to world space coordinates. The result is in Points.
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCPoint convertToWorldSpace ( const CCPoint & nodePoint ) ;
/** Converts a Point to node (local) space coordinates. The result is in Points.
2012-03-23 17:31:28 +08:00
treating the returned / received node point as anchor relative .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCPoint convertToNodeSpaceAR ( const CCPoint & worldPoint ) ;
/** Converts a local Point to world space coordinates.The result is in Points.
2012-03-23 17:31:28 +08:00
treating the returned / received node point as anchor relative .
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCPoint convertToWorldSpaceAR ( const CCPoint & nodePoint ) ;
2012-03-23 17:31:28 +08:00
2012-04-19 14:35:52 +08:00
/** convenience methods which take a CCTouch instead of CCPoint
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCPoint convertTouchToNodeSpace ( CCTouch * touch ) ;
2012-03-23 17:31:28 +08:00
2012-09-17 15:02:24 +08:00
/** converts a CCTouch (world coordinates) into a local coordinate. This method is AR (Anchor Relative).
2012-03-23 17:31:28 +08:00
@ since v0 .7 .1
*/
2012-04-19 14:35:52 +08:00
CCPoint convertTouchToNodeSpaceAR ( CCTouch * touch ) ;
2012-11-14 18:05:15 +08:00
private :
//! lazy allocs
void childrenAlloc ( void ) ;
//! helper that reorder a child
void insertChild ( CCNode * child , int z ) ;
void detachChild ( CCNode * child , bool doCleanup ) ;
CCPoint convertToWindowSpace ( const CCPoint & nodePoint ) ;
2012-03-23 17:31:28 +08:00
} ;
2012-06-20 18:09:11 +08:00
// end of base_node group
/// @}
2012-03-23 17:31:28 +08:00
NS_CC_END
2010-07-07 15:15:30 +08:00
2012-09-17 15:02:24 +08:00
# endif // __PLATFORM_CCNODE_H__
2010-12-24 15:04:26 +08:00
2010-07-07 15:15:30 +08:00