Cocos2d-x结构学习(二)CCNode、CCNodeRGBA、CCRGBAProtocol

前端之家收集整理的这篇文章主要介绍了Cocos2d-x结构学习(二)CCNode、CCNodeRGBA、CCRGBAProtocol前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、CCNode类:继承自CCObject类

class CC_DLL CCNode : public CCObject
{
public:
    CCNode(void);
    virtual ~CCNode(void);
    
    virtual bool init();                       //初始化
    static CCNode * create(void);              //创建一个节点,返回创建节点的指针
    const char* description(void);             //得到一个关于调试信息的字符串,以'\0'结尾
    
    virtual void setZOrder(int zOrder);       //下面3个函数和X序相关
    virtual void _setZOrder(int z);
    virtual int getZOrder();

    virtual void setVertexZ(float vertexZ);    //openGL中Z坐标
    virtual float getVertexZ();

    virtual void setScaleX(float fScaleX);    //x坐标的缩放比例
    virtual float getScaleX();
    virtual void setScaleY(float fScaleY);     //y<span style="font-family: Arial,Helvetica,sans-serif;">坐标的缩放比例</span>
    virtual float getScaleY();
    virtual void setScale(float scale);      //同时改变x、y缩放,1.0f默认
    virtual float getScale();
    virtual void setScale(float fScaleX,float fScaleY);

    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);
    
    virtual void setSkewX(float fSkewX);  //x方向歪斜角度
    virtual float getSkewX();
    virtual void setSkewY(float fSkewY);  <span style="font-family: Arial,sans-serif;">//y方向歪斜角度</span>
    virtual float getSkewY();

    virtual void setAnchorPoint(const CCPoint& anchorPoint);  //锚点相关
    virtual const CCPoint& getAnchorPoint();
    virtual const CCPoint& getAnchorPointInPoints();
    
    virtual void setContentSize(const CCSize& contentSize);   //上下文尺寸相关
    virtual const CCSize& getContentSize() const;

    virtual void setVisible(bool visible);            //是否渲染相关
    virtual bool isVisible();

    virtual void setRotation(float fRotation);         //旋转相关
    virtual float getRotation();
    virtual void setRotationX(float fRotaionX);
    virtual float getRotationX();
    virtual void setRotationY(float fRotationY);
    virtual float getRotationY();

    virtual void setOrderOfArrival(unsigned int uOrderOfArrival);
    virtual unsigned int getOrderOfArrival();
    
    virtual void setGLServerState(ccGLServerState glServerState);   //GL服务状态相关
    virtual ccGLServerState getGLServerState();
    
    virtual void ignoreAnchorPointForPosition(bool ignore);   //锚点忽略相关
    virtual bool isIgnoreAnchorPointForPosition();
    
    virtual void addChild(CCNode * child);                  //添加孩子节点的重载函数
    virtual void addChild(CCNode * child,int zOrder);
    virtual void addChild(CCNode* child,int zOrder,int tag);
   
    virtual CCNode * getChildByTag(int tag);                    //获得孩子节点
    virtual CCArray* getChildren();
    virtual unsigned int getChildrenCount(void) const;
    
    virtual void setParent(CCNode* parent);                      //父节点
    virtual CCNode* getParent();
    
    virtual void removeFromParent();                              //移除节点
    virtual void removeFromParentAndCleanup(bool cleanup);
    virtual void removeChild(CCNode* child);
    virtual void removeChild(CCNode* child,bool cleanup);
    virtual void removeChildByTag(int tag);
    virtual void removeChildByTag(int tag,bool cleanup);
    virtual void removeAllChildren();
    virtual void removeAllChildrenWithCleanup(bool cleanup);
    
    virtual void reorderChild(CCNode * child,int zOrder);   //根据新的Z序重置节点
  
    virtual void sortAllChildren();                           //排序所有节点
   
    virtual CCGridBase* getGrid();                        //网格对象
    virtual void setGrid(CCGridBase *pGrid);
    
    virtual int getTag() const;                            //标签
    virtual void setTag(int nTag);
    
    virtual void* getUserData();                     //用户自定义数据
    virtual void setUserData(void *pUserData);
    virtual CCObject* getUserObject();
    virtual void setUserObject(CCObject *pUserObject);
    
    virtual CCGLProgram* getShaderProgram();                      //openGL着色器相关
    virtual void setShaderProgram(CCGLProgram *pShaderProgram);
    virtual CCCamera* getCamera();                                  //获得摄像机
    
    virtual bool isRunning();                       //判断是否运行

    virtual void registerScriptHandler(int handler);           //脚本处理例程相关   
    virtual void unregisterScriptHandler(void);
    inline int getScriptHandler() { return m_nScriptHandler; };
    
    void scheduleUpdateWithPriorityLua(int nHandler,int priority);     //LUA优先调度更新
    
    virtual void onEnter();                                      //渲染

    virtual void onEnterTransitionDidFinish();              //进入退出
    virtual void onExit();
    virtual void onExitTransitionDidStart();

    virtual void cleanup(void);                      //清理

    virtual void draw(void);                  //绘制

    virtual void visit(void);               //访问

    virtual CCRect boundingBox(void);           //包围盒

    virtual void setActionManager(CCActionManager* actionManager);   //动作、动作管理相关
    virtual CCActionManager* getActionManager();
    CCAction* runAction(CCAction* action);
    void stopAllActions(void);
    void stopAction(CCAction* action);
    void stopActionByTag(int tag);
    CCAction* getActionByTag(int tag);
    unsigned int numberOfRunningActions(void);

    virtual void setScheduler(CCScheduler* scheduler);     //调度相关
    virtual CCScheduler* getScheduler();
    bool isScheduled(SEL_SCHEDULE selector);
    void scheduleUpdate(void);
    void scheduleUpdateWithPriority(int priority);           //根据优先权调度
    void unscheduleUpdate(void);
    void schedule(SEL_SCHEDULE selector,float interval,unsigned int repeat,float delay);
    void schedule(SEL_SCHEDULE selector,float interval);
    void scheduleOnce(SEL_SCHEDULE selector,float delay);
    void schedule(SEL_SCHEDULE selector);
    void unschedule(SEL_SCHEDULE selector);
    void unscheduleAllSelectors(void);
    void resumeSchedulerAndActions(void);
    void pauseSchedulerAndActions(void);
    
    virtual void update(float delta);            //跟新

    void transform(void);                                        //变换
    void transformAncestors(void);
    virtual void updateTransform(void);
    virtual CCAffineTransform nodeToParentTransform(void);
    virtual CCAffineTransform parentToNodeTransform(void);
    virtual CCAffineTransform nodeToWorldTransform(void);
    virtual CCAffineTransform worldToNodeTransform(void);
    CCPoint convertToNodeSpace(const CCPoint& worldPoint);    //空间转换
    CCPoint convertToWorldSpace(const CCPoint& nodePoint);
    CCPoint convertToNodeSpaceAR(const CCPoint& worldPoint);
    CCPoint convertToWorldSpaceAR(const CCPoint& nodePoint);
    CCPoint convertTouchToNodeSpace(CCTouch * touch);
    CCPoint convertTouchToNodeSpaceAR(CCTouch * touch);
    <span style="font-family: Arial,sans-serif;">void setAdditionalTransform(const CCAffineTransform& additionalTransform);</span>
<span style="font-family:Arial,sans-serif;">
</span>    CCComponent* getComponent(const char *pName) const;              //组件
    virtual bool addComponent(CCComponent *pComponent);
    virtual bool removeComponent(const char *pName);
    virtual void removeAllComponents();
 
    void childrenAlloc(void);                          //孩子节点处理
    void insertChild(CCNode* child,int z);
    void detachChild(CCNode *child,bool doCleanup);
    
    CCPoint convertToWindowSpace(const CCPoint& nodePoint);

protected:
    float m_fRotationX;
    float m_fRotationY;
    
    float m_fScaleX;
    float m_fScaleY;
    
    float m_fVertexZ;
    
    CCPoint m_obPosition;
    
    float m_fSkewX;
    float m_fSkewY;
    
    CCPoint m_obAnchorPointInPoints;
    CCPoint m_obAnchorPoint;
    
    CCSize m_obContentSize;
    
    CCAffineTransform m_sAdditionalTransform;
    CCAffineTransform m_sTransform;
    CCAffineTransform m_sInverse;
    
    CCCamera *m_pCamera;
    
    CCGridBase *m_pGrid;
    
    int m_nZOrder;
    
    CCArray *m_pChildren;
    CCNode *m_pParent;
    
    int m_nTag;
    
    void *m_pUserData;
    CCObject *m_pUserObject;
    
    CCGLProgram *m_pShaderProgram;
    
    ccGLServerState m_eGLServerState;
    
    unsigned int m_uOrderOfArrival;
    
    CCScheduler *m_pScheduler;
    
    CCActionManager *m_pActionManager;
    
    bool m_bRunning;
    
    bool m_bTransformDirty;
    bool m_bInverseDirty;
    bool m_bAdditionalTransformDirty;
    bool m_bVisible;
    
    bool m_bIgnoreAnchorPointForPosition;
    bool m_bReorderChildDirty;
    
    int m_nScriptHandler;
    int m_nUpdateScriptHandler;
    ccScriptType m_eScriptType;
    CCComponentContainer *m_pComponentContainer;

};
 
2、<span style="font-family: Arial,sans-serif;">CCNodeRGBA</span>类:继承自CCNode类和CCRGBProtocol类
<pre name="code" class="cpp">class CC_DLL CCNodeRGBA : public CCNode,public CCRGBAProtocol
{
public:
    CCNodeRGBA();
    virtual ~CCNodeRGBA();
    
    virtual bool init();                     //初始化
    static CCNodeRGBA * create(void);      //创建
    
    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) {CC_UNUSED_PARAM(bValue);};
    virtual bool isOpacityModifyRGB() { return false; };

protected:
	GLubyte		_displayedOpacity;
    GLubyte     _realOpacity;
	ccColor3B	_displayedColor;
    ccColor3B   _realColor;
	bool		_cascadeColorEnabled;
    bool        _cascadeOpacityEnabled;
};
 
 
 
</pre>3、CCRGBAProtocol类:</p><p><pre name="code" class="cpp">class CC_DLL CCRGBAProtocol
{
public:
    virtual void setColor(const ccColor3B& color) = 0;
    virtual const ccColor3B& getColor(void) = 0;
    virtual const ccColor3B& getDisplayedColor(void) = 0;
    
    virtual GLubyte getDisplayedOpacity(void) = 0;
    virtual GLubyte getOpacity(void) = 0;
    virtual void setOpacity(GLubyte opacity) = 0;

    virtual void setOpacityModifyRGB(bool bValue) = 0;
    virtual bool isOpacityModifyRGB(void) = 0;
    
    virtual bool isCascadeColorEnabled(void) = 0;
    virtual void setCascadeColorEnabled(bool cascadeColorEnabled) = 0;
    
    virtual void updateDisplayedColor(const ccColor3B& color) = 0;
 
    virtual void updateDisplayedOpacity(GLubyte opacity) = 0;
};
原文链接:https://www.f2er.com/cocos2dx/343831.html

猜你在找的Cocos2d-x相关文章