Cocos2d-x结构学习(六)CCScene、CCSprite、CCTextureProtocol、CCBlendProtocol、CCGLBufferedNode

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

1、CCScene:很简单的场景类,继承自CCNode,大多数情况可继承他来构造场景

class CC_DLL CCScene : public CCNode
{
public:
    CCScene();
    virtual ~CCScene();
    bool init();                         //初始化

    static CCScene *create(void);        //创建场景
};
2、CCSprite(精灵):继承自CCNodeRGBA,CCTextureProtocol,另外还可以根据需要继承CCGLBufferedNode
class CC_DLL CCSprite : public CCNodeRGBA,public CCTextureProtocol
#ifdef EMSCRIPTEN,public CCGLBufferedNode
#endif
{
public:
    static CCSprite* create();                  //多种方法创建一个精灵
    static CCSprite* create(const char *pszFileName);
    static CCSprite* create(const char *pszFileName,const CCRect& rect);
    static CCSprite* createWithTexture(CCTexture2D *pTexture);
    static CCSprite* createWithTexture(CCTexture2D *pTexture,const CCRect& rect);
    static CCSprite* createWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
    static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName);
    
    CCSprite(void);
    virtual ~CCSprite(void);
    virtual bool init(void);                  //多种方法初始化
    virtual bool initWithTexture(CCTexture2D *pTexture);
    virtual bool initWithTexture(CCTexture2D *pTexture,const CCRect& rect);
    virtual bool initWithTexture(CCTexture2D *pTexture,const CCRect& rect,bool rotated);
    virtual bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
    virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName);
    virtual bool initWithFile(const char *pszFilename);
    virtual bool initWithFile(const char *pszFilename,const CCRect& rect);
    
    inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; }    //得到混合函数
   
    virtual void setPosition(const CCPoint& pos);                       //几个位置相关函数
    virtual void setRotation(float fRotation);
    virtual void setRotationX(float fRotationX);
    virtual void setRotationY(float fRotationY);
    virtual void setSkewX(float sx);
    virtual void setSkewY(float sy);
    virtual void removeChild(CCNode* pChild,bool bCleanup);                     //几个孩子节点相关函数
    virtual void removeAllChildrenWithCleanup(bool bCleanup);
    virtual void reorderChild(CCNode *pChild,int zOrder);
    virtual void addChild(CCNode *pChild);
    virtual void addChild(CCNode *pChild,int zOrder);
    virtual void addChild(CCNode *pChild,int zOrder,int tag);
    virtual void sortAllChildren();
    virtual void setScale(float fScale);                             //设置缩放比例
    virtual void setVertexZ(float fVertexZ);                         //设置Z坐标
    virtual void setAnchorPoint(const CCPoint& anchor);             //两个锚点相关函数
    virtual void ignoreAnchorPointForPosition(bool value);
    virtual void setVisible(bool bVisible);                        //设置是否可见
    virtual void draw(void);                                     //绘制
   
    virtual void setColor(const ccColor3B& color3);                       //几个RGB颜色相关和显示相关函数
    virtual void updateDisplayedColor(const ccColor3B& parentColor);
    virtual void setOpacity(GLubyte opacity);
    virtual void setOpacityModifyRGB(bool modify);
    virtual bool isOpacityModifyRGB(void);
    virtual void updateDisplayedOpacity(GLubyte parentOpacity);
    
    virtual void updateTransform(void);                               //更新变换(旋转,缩放,平移)
    
    virtual CCSpriteBatchNode* getBatchNode(void);               //获得和设置批处理节点对象
    virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
     
    virtual void setTextureRect(const CCRect& rect);                                              //几个矩形设置相关函数
    virtual void setTextureRect(const CCRect& rect,bool rotated,const CCSize& untrimmedSize);
    virtual void setVertexRect(const CCRect& rect);
    
    virtual void setDisplayFrame(CCSpriteFrame *pNewFrame);                //帧及动画相关函数
    virtual bool isFrameDisplayed(CCSpriteFrame *pFrame);
    virtual CCSpriteFrame* displayFrame(void);
    virtual void setDisplayFrameWithAnimationName(const char *animationName,int frameIndex);
    
    inline virtual bool isDirty(void) { return m_bDirty; }                      //淡入淡出
    inline virtual void setDirty(bool bDirty) { m_bDirty = bDirty; }
    
    inline ccV3F_C4B_T2F_Quad getQuad(void) { return m_sQuad; }
    inline bool isTextureRectRotated(void) { return m_bRectRotated; }
    inline unsigned int getAtlasIndex(void) { return m_uAtlasIndex; }
    inline void setAtlasIndex(unsigned int uAtlasIndex) { m_uAtlasIndex = uAtlasIndex; }

    inline const CCRect& getTextureRect(void) { return m_obRect; }                   //获得纹理矩形

    inline CCTextureAtlas* getTextureAtlas(void) { return m_pobTextureAtlas; }
    inline void setTextureAtlas(CCTextureAtlas *pobTextureAtlas) { m_pobTextureAtlas = pobTextureAtlas; }

    inline const CCPoint& getOffsetPosition(void) { return m_obOffsetPosition; }            //设置偏移位置

    bool isFlipX(void);                               //翻转相关的函数
    void setFlipX(bool bFlipX);
    bool isFlipY(void);
    void setFlipY(bool bFlipY);
protected:
    void updateColor(void);
    virtual void setTextureCoords(CCRect rect);
    virtual void updateBlendFunc(void);
    virtual void setReorderChildDirtyRecursively(void);
    virtual void setDirtyRecursively(bool bValue);

    CCTextureAtlas*     m_pobTextureAtlas;
    unsigned int        m_uAtlasIndex;
    CCSpriteBatchNode*  m_pobBatchNode;
    
    bool                m_bDirty;
    bool                m_bRecursiveDirty;
    bool                m_bHasChildren;
    bool                m_bShouldBeHidden;
    CCAffineTransform   m_transformToBatch;
    
    ccBlendFunc        m_sBlendFunc;
    CCTexture2D*       m_pobTexture;

    CCRect m_obRect;
    bool   m_bRectRotated;

    CCPoint m_obOffsetPosition;
    CCPoint m_obUnflippedOffsetPositionFromCenter;

    ccV3F_C4B_T2F_Quad m_sQuad;

    bool m_bOpacityModifyRGB;

    bool m_bFlipX; 
    bool m_bFlipY;
};
3、CCTextureProtocol:纹理(协议)底层处理类,继承自CCBlendProtocol,很简单,只有两个函数,设置和获得纹理对象
class CC_DLL CCTextureProtocol : public CCBlendProtocol
{
public:
    virtual CCTexture2D* getTexture(void) = 0;
    virtual void setTexture(CCTexture2D *texture) = 0;
};
4、CCBlendProtocol:混合(协议)底层接口类,很简单,两函数分别是设置和获得混合对象
class CC_DLL CCBlendProtocol
{
public:
    virtual void setBlendFunc(ccBlendFunc blendFunc) = 0;
    virtual ccBlendFunc getBlendFunc(void) = 0;
};
5、CCGLBufferedNode:openGL缓冲节点类
class CCGLBufferedNode
{
public:
    CCGLBufferedNode(void);

    void setGLBufferData(void *buf,GLuint bufSize,int slot);   //设置缓冲数据
    void setGLIndexData(void *buf,int slot);

#define BUFFER_SLOTS 4
    GLuint m_bufferObject[BUFFER_SLOTS];
    GLuint m_bufferSize[BUFFER_SLOTS];

    GLuint m_indexBufferObject[BUFFER_SLOTS];
    GLuint m_indexBufferSize[BUFFER_SLOTS];
};

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