CCNode(成员ContentSize Camera Grid Child Par UserData Scheduler ActionManager ComponentContainer+颜色节点)

本文深入探讨了CCNode类的使用与特性,包括节点的基本属性、操作方法、事件回调等,提供了丰富的示例帮助开发者更好地理解并运用CCNode进行游戏开发。

#ifndef __PLATFORM_CCNODE_H__

#define __PLATFORM_CCNODE_H__


#include "ccMacros.h"

#include "cocoa/CCAffineTransform.h"

#include "cocoa/CCArray.h"

#include "CCGL.h"

#include "shaders/ccGLStateCache.h"

#include "shaders/CCGLProgram.h"

#include "kazmath/kazmath.h"

#include "script_support/CCScriptSupport.h"

#include "CCProtocols.h"


NS_CC_BEGIN


class CCCamera;

class CCGridBase;

class CCPoint;

class CCTouch;

class CCAction;

class CCRGBAProtocol;

class CCLabelProtocol;

class CCScheduler;

class CCActionManager;

class CCComponent;

class CCDictionary;

class CCComponentContainer;


enum {

    kCCNodeTagInvalid = -1,  //设定节点标签无效值 -1  枚举成员kCCNodeTagInvalid

};


enum {

    kCCNodeOnEnter,                   //状态枚举类型  成员:。。

    kCCNodeOnExit,

    kCCNodeOnEnterTransitionDidFinish,

    kCCNodeOnExitTransitionDidStart,

    kCCNodeOnCleanup

};


/** @brief CCNode is the main element. Anything that 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)      //按周期回调  即每帧update

 - 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              //重写draw 来渲染节点


 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 // opengl 中节点z轴值


 Default values:   //默认值

 - rotation: 0

 - position: (x=0,y=0) // 位置默认 0 0 

 - scale: (x=1,y=1)

 - contentSize: (x=0,y=0)  

 - anchorPoint: (x=0,y=0)  // 锚点默认 0 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)   //根据camera值 move

 -# The grid will render the captured screen                         //格子渲染捕获的screen


 Camera:

 - Each node has a camera. By default(默认情况下) it points to(指向) the center of the CCNode.//camera默认指向节点的中心

 */


class CC_DLL CCNode : public CCObject

{

public:

    CCNode(void);

    virtual ~CCNode(void);

    

    /** Initializes the instance(实例) of CCNode*/

    virtual bool init();


/*** Allocates(分配) and initializes a node.*/

    static CCNode * create(void);

    

    /** * Gets the description string. It makes debugging(排除故障) easier. */

    const char* description(void);

   

     /**

     * Sets the Z order which stands for the drawing order, and reorder this node in its parent's children array.

     *

     * The Z order of node is relative to(相对于) its "brothers": children of the same parent.

     * It's nothing to do with OpenGL's z vertex. This one only affects the draw order of nodes in cocos2d.

     * The larger number it is, the later this node will be drawn in each message loop.

     * Please refer(参考) to setVertexZ(float) for the difference.

     */

    virtual void setZOrder(int zOrder);//设置ZOrderset之后会重新排序 仅仅影响draw先后  是一个相对于兄弟节点的值 不同于setVertexZ(float)设置OpenGL的 z值    


    /**

     * Sets the z order which stands for the drawing order

     *

     * This is an internal method. Don't call it outside the framework.

     * The difference between setZOrder(int) and _setOrder(int) is:

     * - _setZOrder(int) is a pure setter for m_nZOrder memeber variable

     * - setZOrder(int) firstly changes m_nZOrder, then recorder this node in its parent's chilren array.

     */

    virtual void _setZOrder(int z);//设置ZOrder 不重排


    virtual int getZOrder();//得到 ZOrder


    /**

     * Sets 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 2D projection

     * - cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0 

    //只有当openggl z值相同时 cocos2d Z值才有意义

     * @warning Use it at your own risk(由自己负责) since it might break the cocos2d parent-children z order

  //小心使用VertexZ 会影响到cocos2dx Z

     */


//设置 得到 VertexZ

    virtual void setVertexZ(float vertexZ);

    virtual float getVertexZ();


//scale

    virtual void setScaleX(float fScaleX);

    virtual float getScaleX();   

    virtual void setScaleY(float fScaleY);

    virtual float getScaleY();

    virtual void setScale(float scale);


    virtual float getScale();//只有当想x y相同时有效 内部断言了Assert when m_fScaleX != m_fScaleY.

    

    //position 

    virtual void setPosition(const CCPoint &position);

    virtual const CCPoint& getPosition();

    virtual void setPosition(float x, float y);

    virtual void getPosition(float* x, float* y);//参数是指针!

   

    virtual void  setPositionX(float x);

    virtual float getPositionX(void);

    virtual void  setPositionY(float y);

    virtual float getPositionY(void);

    

 //扭曲  

    /**

     * Changes 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.

     */

    virtual void setSkewX(float fSkewX);

    virtual float getSkewX();

    virtual void setSkewY(float fSkewY);

    virtual float getSkewY();


 //锚点   

    /**

     * Sets the anchor point in percent.

//所有转变 和 位置变化 都受到锚点影响

     * 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.

//默认值 0.5 0.5

     * The default anchorPoint is (0.5,0.5), so it starts in the center of the node.

     */

    virtual void setAnchorPoint(const CCPoint& anchorPoint);

    

    virtual const CCPoint& getAnchorPoint();

   

 /**

     * Returns the anchorPoint in absolute pixels. //返回锚点确定的像素点位置 

     * @warning You can only read it. If you wish to modify it, use anchorPoint instead.//可读 不建议修改 可以直接用anchorPoint改锚点位置

     */

    virtual const CCPoint& getAnchorPointInPoints();

    

  //ContentSize  

    /**

     * Sets the untransformed size of the node.

     *

     * The contentSize remains the same no matter(不论怎样) the node is scaled or rotated.//contentSize大小不受scaled or rotated影响 

     * All nodes has a size. Layer and Scene has the same size of the screen.//所有节点有大小 层和场景大小 = 屏幕大小

     */

    virtual void setContentSize(const CCSize& contentSize);


    virtual const CCSize& getContentSize() const;


//Visible

    virtual void setVisible(bool visible);

    virtual bool isVisible();


//Rotation

    virtual void setRotation(float fRotation);

    virtual float getRotation();

    virtual void setRotationX(float fRotaionX);

    virtual float getRotationX();

    virtual void setRotationY(float fRotationY);

    virtual float getRotationY();


  //OrderOfArrival(影响渲染先后)  当addchild时 并没有设置Zorder(默认0) 但会有先后渲染 因为越后add  OrderOfArrival越大 ~内部函数 禁止使用 !

    virtual void setOrderOfArrival(unsigned int uOrderOfArrival);

    virtual unsigned int getOrderOfArrival();

    

  //设置opengl服务支持的状态 

    /** * Sets the state of OpenGL server side.*/

    virtual void setGLServerState(ccGLServerState glServerState);

    virtual ccGLServerState getGLServerState();

    

    

    /**

     * Sets whether the anchor point will be (0,0) when you position this node. 

     *

     * This is an internal method, only used by CCLayer and CCScene. Don't call it outside framework(框架).

     * The default value is false, while in CCLayer and CCScene are true

     *

     * @param ignore    true if anchor point will be (0,0) when you position this node

     * @todo This method shoud be renamed as setIgnoreAnchorPointForPosition(bool) or something with "set"

     */

//移动节点时是否无视锚点(视为0 0)内部函数 禁止调用

    virtual void ignoreAnchorPointForPosition(bool ignore); 

    virtual bool isIgnoreAnchorPointForPosition();

    

    /** 

     * Adds a child to the container with z-order as 0.

     * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately(立即的).

     */

//加入 得到 子节点

    virtual void addChild(CCNode * child);

    virtual void addChild(CCNode * child, int zOrder);

    virtual void addChild(CCNode* child, int zOrder, int tag);


    CCNode * getChildByTag(int tag);

    virtual CCArray* getChildren();

    

//得到子节点数

    unsigned int getChildrenCount(void) const;

    

//为节点设置父节点

    virtual void setParent(CCNode* parent);


//得到父节点

    virtual CCNode* getParent();

    

   

    

//删除节点自身 并且cleanup

    virtual void removeFromParent();


//删除节点自身 1、是否cleanup

    virtual void removeFromParentAndCleanup(bool cleanup);


//从子节点数组中删除一个子节点(this含有一个子节点数组 每次add都会加入数组)并且cleanup? 参数是节点指针 

    virtual void removeChild(CCNode* child);

    virtual void removeChild(CCNode* child, bool cleanup);

//参数是子节点tag 并且cleanup?

    virtual void removeChildByTag(int tag);

    virtual void removeChildByTag(int tag, bool cleanup);

//清空m_pChildren

    virtual void removeAllChildren();

    virtual void removeAllChildrenWithCleanup(bool cleanup);

    

    /** 

     * Reorders a child according to a new z value.

*/

//重新设置一个子节点的zorder 1、子节点指针 2、zorder

    virtual void reorderChild(CCNode * child, int zOrder);

    

    /** 

     * Sorts the children array once before drawing, instead of every time when a child is added or reordered. 

//drawing 前重排 而不是每次add或者重新设置order时重排

     * This approach(方法) can improves(改善) the performance(性能) massively(大量的).

     * @note Don't call this manually(手动的) unless a child added needs to be removed in the same frame(框架 结构)//??????

     */

//排列节点 慎用

    virtual void sortAllChildren();    

    /**

     * Returns a grid object that is used when applying effects

     */

//返回一个用于特效的格子指针

    virtual CCGridBase* getGrid();

//设置用于特效的格子指针

    virtual void setGrid(CCGridBase *pGrid);

    

//设置 得到标签tag

    virtual int getTag() const;

    virtual void setTag(int nTag);

    

//设置 得到绑定的 userData(指针->一般都是指针 或 结构体 或者object等任何)   在节点释放或者改变绑定指针时 需要手动release这个userdata  

    virtual void* getUserData();

    virtual void setUserData(void *pUserData);

    

    virtual CCObject* getUserObject();

    virtual void setUserObject(CCObject *pUserObject);

    


    

    

    /// @{

    /// @name Shader Program

    /**

     * Return the shader program currently used for this node

     */

// ????????

    virtual CCGLProgram* getShaderProgram();

    /**

     * Sets the shader program for this node

     *

     * Since v2.0, each rendering node must set its shader program.

     * It should be set in initialize phase.

     * @code

     * node->setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));

     * @endcode

     * 

     * @param The shader program which fetchs from CCShaderCache.

     */

    virtual void setShaderProgram(CCGLProgram *pShaderProgram);

    /// @} end of Shader Program

    

    

    /**

     * Returns a camera object that lets you move the node using a gluLookAt

     *

     * @code

     * CCCamera* camera = node->getCamera();

     * camera->setEyeXYZ(0, 0, 415/2);

     * camera->setCenterXYZ(0, 0, 0);


     */

//得到节点的摄像机 可以通过gluLookAt 改变节点位置

    virtual CCCamera* getCamera();

    

    /** 

     * Returns whether or not the node accepts event callbacks.

     * 

     * Running means the node accept event callbacks like onEnter(), onExit(), update()

     */

//是否接受 event callbacks like onEnter(), onExit(), update()

    virtual bool isRunning();


    /**

     * Registers a script function that will be called in onEnter() & onExit() seires functions.

     * 

     * This handler will be removed automatically after onExit() called.

     * @code

     * -- lua sample

     * local function sceneEventHandler(eventType)

     *     if eventType == kCCNodeOnEnter then

     *         -- do something

     *     elseif evetType == kCCNodeOnExit then

     *         -- do something

     *     end

     * end

     * scene::registerScriptHandler(sceneEventHandler)

     * @endcode

     *

     * @warning This method is for internal usage, don't call it manually.

     * @todo Perhaps we should rename it to get/set/removeScriptHandler acoording to the function name style.

     *

     * @param handler   A number that indicates a lua function. 

     */

//????????????????????

    virtual void registerScriptHandler(int handler);

    /**

     * Unregisters a script function that will be called in onEnter() & onExit() series functions.

     *

     * @see registerScriptHandler(int)

     */

    virtual void unregisterScriptHandler(void);

    /**

     * Gets script handler for onEnter/onExit event.

     * This is an internal method. g

     * @see registerScriptHandler(int)

     *

     * @return A number that indicates a lua function.

     */

    inline int getScriptHandler() { return m_nScriptHandler; };

    

    /** 

     * Schedules for lua script. 

     */

    void scheduleUpdateWithPriorityLua(int nHandler, int priority);

    

    /// @}  end Script Bindings



    /// @{

    /// @name Event Callbacks

    

    /** 

     * Event callback that is invoked every time when CCNode enters the 'stage'.

     * If the CCNode enters the 'stage' with a transition, this event is called when the transition starts.

     * During onEnter you can't access a "sister/brother" node.

     * If you override onEnter, you shall call its parent's one, e.g., CCNode::onEnter().

     */

//节点进入舞台前所要处理的

    virtual void onEnter();


    /** Event callback that is invoked when the CCNode enters in the 'stage'.

     * If the CCNode enters the 'stage' with a transition, this event is called when the transition finishes.

     * If you override onEnterTransitionDidFinish, you shall call its parent's one, e.g. CCNode::onEnterTransitionDidFinish()

     */

//...?????

    virtual void onEnterTransitionDidFinish();


    /** 

     * Event callback that is invoked every time the CCNode leaves the 'stage'.

     * If the CCNode leaves the 'stage' with a transition, this event is called when the transition finishes.

     * During onExit you can't access a sibling node.

     * If you override onExit, you shall call its parent's one, e.g., CCNode::onExit().

     */

//节点离开舞台所要处理的

    virtual void onExit();


    /** 

     * Event 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();


//终止节点所有运行的actions 和 schedulers

    virtual void cleanup(void);


    /** 

     * Override this method to draw your own node.        //重写这个方法draw自己的node

     * The following GL states will be enabled by default://gl设置

     * - 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.

     */

//渲染

    virtual void draw(void);


    /** 

     * Visits this node's children and draw them recursively(递归的).

     */

//访问节点的子节点 并递归的渲染子节点

    virtual void visit(void);


    

    /** 

     * Returns a "local" axis(轴) aligned(对齐的) bounding(边界框) box of the node.

     * The returned box is relative only to its parent.

     * @note This method returns a temporaty variable, so it can't returns const CCRect&

     */

//得到包围盒 boundingBox

    CCRect boundingBox(void);

CCRect CCNode::boundingBox()

{

    CCRect rect = CCRectMake(0, 0, m_obContentSize.width, m_obContentSize.height);

    return CCRectApplyAffineTransform(rect, nodeToParentTransform());

}



    /**

     * Sets the CCActionManager object that is used by all actions.

     *

     * @warning If you set a new CCActionManager, then previously(以前) created actions will be removed.

     *

     */

//为节点设置动作管理器 如果重新设置 之前创建的动作会被移除

    virtual void setActionManager(CCActionManager* actionManager);

//得到节点的动过管理器

    virtual CCActionManager* getActionManager();

    

    /** 

     * Executes(执行) an action, and returns the action that is executed.

     *

     * This node becomes(成为) the action's target. Refer to CCAction::getTarget()

     * @warning Actions don't retain their target.

     */

//执行动作 1、返回动作本身(targete为调用节点)  并没有retain调用节点 所以不要remove

    CCAction* runAction(CCAction* action);


    /** 

     * Stops and removes all actions from the running action list .

     */

//停止 并且移除所有action  m_pActionManager(每个node都有一个动作管理器(同一个单例) 容纳所有node动作)中得actions

    void stopAllActions(void);

//停止 并且移除m_pActionManager指定action 

    void stopAction(CCAction* action);

//停止 并且移除m_pActionManager中指定tag的action 

    void stopActionByTag(int tag);


    CCAction* getActionByTag(int tag);


    /** 

     * 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. 

     */

//得到running 和 即将run的 action数目

    unsigned int numberOfRunningActions(void);

     

//设置update回调

    virtual void setScheduler(CCScheduler* scheduler);


//得到回调 update回调(导演的成员 调度器)

    virtual CCScheduler* getScheduler();

// ccnode 初始化中一段

 m_pScheduler = director->getScheduler();

    m_pScheduler->retain();

//


//检查参数回调事件是否在调度器中

    bool isScheduled(SEL_SCHEDULE selector);


//把update函数放入调度器中 每帧回调

    void scheduleUpdate(void);

//把update函数放入调度器中指定优先级 每帧回调

    void scheduleUpdateWithPriority(int priority);

//把update从调度器中移除

    void unscheduleUpdate(void);


    /**

     * Schedules a custom selector.

     *

     * If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.

     * @code

     * // firstly, implement a schedule function

     * void MyNode::TickMe(float dt);

     * // wrap this function into a selector via schedule_selector marco.

     * this->schedule(schedule_selector(MyNode::TickMe), 0, 0, 0);

     * @endcode

     *

     * @param interval  Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate()             instead.

     * @param repeat    The selector will be excuted (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.

     * @param delay     The amount of time that the first tick will wait before execution.

     */

//参数用于create一个 custom selector。 create一个selector并add到m_pScheduler调度器中

    void schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay);

 

void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay)

{

    CCAssert( selector, "Argument must be non-nil");

    CCAssert( interval >=0, "Argument must be positive");


    m_pScheduler->scheduleSelector(selector, this, interval , repeat, delay, !m_bRunning);

 //m_pScheduler = director->getScheduler(); m_pScheduler->retain(); m_pScheduler是ccnode成员

}

//custom selector

    void schedule(SEL_SCHEDULE selector, float interval);

    

//将一个事件(selector)加入调度器(时间轴) 在delay秒后触发

    void scheduleOnce(SEL_SCHEDULE selector, float delay);

    

//custom selector interval=0

    void schedule(SEL_SCHEDULE selector);

    

//删除时间轴上(调度器)的一个事件

    void unschedule(SEL_SCHEDULE selector);


//删除所有

    void unscheduleAllSelectors(void);



//启动所有事件 和 动作 在onEnter中调用

    void resumeSchedulerAndActions(void);

    /** 

     * Pauses all scheduled selectors and actions.

     * This method is called internally by onExit

     */

//暂停所有事件 和 动作 在onExit中调用

    void pauseSchedulerAndActions(void);

    

//调用scheduleUpdate()后 节点的update将会每帧调用

    virtual void update(float delta);

    

    /**

     * Performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes.

     */

    void transform(void);

    /**

     * 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.

     */

//.........................

    void transformAncestors(void);

    /**

     * Calls children's updateTransform() method recursively.

     *

     * This method is moved from CCSprite, so it's no longer specific to CCSprite.

     * As the result, you apply CCSpriteBatchNode's optimization on your customed CCNode.

     * e.g., batchNode->addChild(myCustomNode), while you can only addChild(sprite) before.

     */

//.........................

    virtual void updateTransform(void);

    

    /** 

     * Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.

     * The matrix is in Pixels.

     */

//.........................

    virtual CCAffineTransform nodeToParentTransform(void);


    /** 

     * Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.

     * The matrix is in Pixels.

     */

//.........................

    virtual CCAffineTransform parentToNodeTransform(void);


    /** 

     * Returns the world affine transform matrix. The matrix is in Pixels.

     */

//.........................

    virtual CCAffineTransform nodeToWorldTransform(void);


    /** 

     * Returns the inverse world affine transform matrix. The matrix is in Pixels.

     */

//.........................

    virtual CCAffineTransform worldToNodeTransform(void);


    /// @} end of Transformations

    

    


 //坐标转换   

// Converts(转变) a Point to node (local) space coordinates. The result is in Points.


    CCPoint convertToNodeSpace(const CCPoint& worldPoint);

    


//Converts a Point to world space coordinates. The result is in Points.

    CCPoint convertToWorldSpace(const CCPoint& nodePoint);

    

    /** 

     * Converts a Point to node (local) space coordinates. The result is in Points.

     * treating the returned/received node point as anchor relative.

     */

    CCPoint convertToNodeSpaceAR(const CCPoint& worldPoint);

    

    /** 

     * Converts a local Point to world space coordinates.The result is in Points.

     * treating the returned/received node point as anchor relative.

     */

    CCPoint convertToWorldSpaceAR(const CCPoint& nodePoint);


    /** 

     * convenience methods which take a CCTouch instead of CCPoint

     */

    CCPoint convertTouchToNodeSpace(CCTouch * touch);


    /** 

     * converts a CCTouch (world coordinates) into a local coordinate. This method is AR (Anchor Relative).

     */

    CCPoint convertTouchToNodeSpaceAR(CCTouch * touch);

    

/**

     *  Sets the additional transform.

     *

     *  @note The additional transform will be concatenated at the end of nodeToParentTransform.

     *        It could be used to simulate `parent-child` relationship between two nodes (e.g. one is in BatchNode, another isn't).

     *  @code

        // create a batchNode

        CCSpriteBatchNode* batch= CCSpriteBatchNode::create("Icon-114.png");

        this->addChild(batch);

     

        // create two sprites, spriteA will be added to batchNode, they are using different textures.

        CCSprite* spriteA = CCSprite::createWithTexture(batch->getTexture());

        CCSprite* spriteB = CCSprite::create("Icon-72.png");


        batch->addChild(spriteA); 

     

        // We can't make spriteB as spriteA's child since they use different textures. So just add it to layer.

        // But we want to simulate `parent-child` relationship for these two node.

        this->addChild(spriteB); 


        //position

        spriteA->setPosition(ccp(200, 200));

     

        // Gets the spriteA's transform.

        CCAffineTransform t = spriteA->nodeToParentTransform();

     

        // Sets the additional transform to spriteB, spriteB's postion will based on its pseudo parent i.e. spriteA.

        spriteB->setAdditionalTransform(t);


        //scale

        spriteA->setScale(2);

     

        // Gets the spriteA's transform.

        t = spriteA->nodeToParentTransform();

     

        // Sets the additional transform to spriteB, spriteB's scale will based on its pseudo parent i.e. spriteA.

        spriteB->setAdditionalTransform(t);


        //rotation

        spriteA->setRotation(20);

     

        // Gets the spriteA's transform.

        t = spriteA->nodeToParentTransform();

     

        // Sets the additional transform to spriteB, spriteB's rotation will based on its pseudo parent i.e. spriteA.

        spriteB->setAdditionalTransform(t);

     *  @endcode

     */

    void setAdditionalTransform(const CCAffineTransform& additionalTransform);

    

    /// @} end of Coordinate Converters


      /// @{

    /// @name component functions

    /** 

     *   gets a component by its name

     */

//


//以下关于组件的 一些函数

    CCComponent* getComponent(const char *pName) const;

    

    /** 

     *   adds a component

     */

    virtual bool addComponent(CCComponent *pComponent);

    

    /** 

     *   removes a component by its name      

     */

    virtual bool removeComponent(const char *pName);

    

    /**

     *   removes all components

     */

    virtual void removeAllComponents();

    /// @} end of component functions


private:

    /// lazy allocs

    void childrenAlloc(void);

    

    /// helper that reorder a child

    void insertChild(CCNode* child, int z);

    

    /// Removes a child, call child->onExit(), do cleanup, remove it from children array.

    void detachChild(CCNode *child, bool doCleanup);

    

    /// Convert cocos2d coordinates to UI windows coordinate.

    CCPoint convertToWindowSpace(const CCPoint& nodePoint);


protected:

    float m_fRotationX;                 ///< rotation angle on x-axis

    float m_fRotationY;                 ///< rotation angle on y-axis

    

    float m_fScaleX;                    ///< scaling factor on x-axis

    float m_fScaleY;                    ///< scaling factor on y-axis

    

    float m_fVertexZ;                   ///< OpenGL real Z vertex

    

    CCPoint m_obPosition;               ///< position of the node

    

    float m_fSkewX;                     ///< skew angle on x-axis

    float m_fSkewY;                     ///< skew angle on y-axis

    

    CCPoint m_obAnchorPointInPoints;    ///< anchor point in points

    CCPoint m_obAnchorPoint;            ///< anchor point normalized (NOT in points)

    

    CCSize m_obContentSize;             ///< untransformed size of the node

    

    

    CCAffineTransform m_sAdditionalTransform; ///< transform

    CCAffineTransform m_sTransform;     ///< transform

    CCAffineTransform m_sInverse;       ///< transform

    

    CCCamera *m_pCamera;                ///< a camera

    

    CCGridBase *m_pGrid;                ///< a grid

    

    int m_nZOrder;                      ///< z-order value that affects the draw order

    

    CCArray *m_pChildren;               ///< array of children nodes

    CCNode *m_pParent;                  ///< weak reference to parent node

    

    int m_nTag;                         ///< a tag. Can be any number you assigned just to identify this node

    

    void *m_pUserData;                  ///< A user assingned void pointer, Can be point to any cpp object

    CCObject *m_pUserObject;            ///< A user assigned CCObject

    

    CCGLProgram *m_pShaderProgram;      ///< OpenGL shader

    

    ccGLServerState m_eGLServerState;   ///< OpenGL servier side state

    

    unsigned int m_uOrderOfArrival;     ///< used to preserve sequence while sorting children with the same zOrder

    

    CCScheduler *m_pScheduler;          ///< scheduler used to schedule timers and updates

    

    CCActionManager *m_pActionManager; ///动作管理类单例 控制所有动作

    

    bool m_bRunning;                    ///< is running

    

    bool m_bTransformDirty;             ///< transform dirty flag

    bool m_bInverseDirty;               ///< transform dirty flag

    bool m_bAdditionalTransformDirty;   ///< The flag to check whether the additional transform is dirty

    bool m_bVisible;                    ///< is this node visible

    

    bool m_bIgnoreAnchorPointForPosition; ///< true if the Anchor Point will be (0,0) when you position the CCNode, false otherwise.

                                          ///< Used by CCLayer and CCScene.

    

    bool m_bReorderChildDirty;          ///< children order dirty flag

    

    int m_nScriptHandler;               ///< script handler for onEnter() & onExit(), used in Javascript binding and Lua binding.

    int m_nUpdateScriptHandler;         ///< script handler for update() callback per frame, which is invoked from lua & javascript.

    ccScriptType m_eScriptType;         ///< type of script binding, lua or javascript

    

    CCComponentContainer *m_pComponentContainer;        ///< Dictionary of components


};


//#pragma mark - CCNodeRGBA


/** CCNodeRGBA is a subclass of CCNode that implements the CCRGBAProtocol protocol.

 

 All features from CCNode are valid, plus the following new features:

 - opacity

 - RGB colors

 

 Opacity/Color propagates into children that conform to the CCRGBAProtocol if cascadeOpacity/cascadeColor is enabled.

 @since v2.1

 */

class CC_DLL CCNodeRGBA : public CCNode, public CCRGBAProtocol  //有颜色的节点 

{

public:

    CCNodeRGBA();

    virtual ~CCNodeRGBA();

    

    virtual bool init();

    

    virtual GLubyte getOpacity();

    virtual GLubyte getDisplayedOpacity();

    virtual void setOpacity(GLubyte opacity);

    virtual void updateDisplayedOpacity(GLubyte parentOpacity);

    virtual bool isCascadeOpacityEnabled();

    virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);

    

    virtual const ccColor3B& getColor(void);

    virtual const ccColor3B& getDisplayedColor();

    virtual void setColor(const ccColor3B& color);

    virtual void updateDisplayedColor(const ccColor3B& parentColor);

    virtual bool isCascadeColorEnabled();

    virtual void setCascadeColorEnabled(bool cascadeColorEnabled);

    

    virtual void setOpacityModifyRGB(bool bValue) {};

    virtual bool isOpacityModifyRGB() { return false; };


protected:

GLubyte_displayedOpacity;

    GLubyte     _realOpacity;

ccColor3B_displayedColor;

    ccColor3B   _realColor;

bool_cascadeColorEnabled;

    bool        _cascadeOpacityEnabled;

};


// end of base_node group

/// @}


NS_CC_END


#endif // __PLATFORM_CCNODE_H__


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值