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

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

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

  1. class CC_DLL CCScene : public CCNode
  2. {
  3. public:
  4. CCScene();
  5. virtual ~CCScene();
  6. bool init(); //初始化
  7.  
  8. static CCScene *create(void); //创建场景
  9. };
2、CCSprite(精灵):继承自CCNodeRGBA,CCTextureProtocol,另外还可以根据需要继承CCGLBufferedNode
  1. class CC_DLL CCSprite : public CCNodeRGBA,public CCTextureProtocol
  2. #ifdef EMSCRIPTEN,public CCGLBufferedNode
  3. #endif
  4. {
  5. public:
  6. static CCSprite* create(); //多种方法创建一个精灵
  7. static CCSprite* create(const char *pszFileName);
  8. static CCSprite* create(const char *pszFileName,const CCRect& rect);
  9. static CCSprite* createWithTexture(CCTexture2D *pTexture);
  10. static CCSprite* createWithTexture(CCTexture2D *pTexture,const CCRect& rect);
  11. static CCSprite* createWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
  12. static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName);
  13. CCSprite(void);
  14. virtual ~CCSprite(void);
  1. virtual bool init(void); //多种方法初始化
  2. virtual bool initWithTexture(CCTexture2D *pTexture);
  3. virtual bool initWithTexture(CCTexture2D *pTexture,const CCRect& rect);
  4. virtual bool initWithTexture(CCTexture2D *pTexture,const CCRect& rect,bool rotated);
  5. virtual bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
  6. virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName);
  7. virtual bool initWithFile(const char *pszFilename);
  8. virtual bool initWithFile(const char *pszFilename,const CCRect& rect);
  9. inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; } //得到混合函数
  10. virtual void setPosition(const CCPoint& pos); //几个位置相关函数
  11. virtual void setRotation(float fRotation);
  12. virtual void setRotationX(float fRotationX);
  13. virtual void setRotationY(float fRotationY);
  14. virtual void setSkewX(float sx);
  15. virtual void setSkewY(float sy);
  16. virtual void removeChild(CCNode* pChild,bool bCleanup); //几个孩子节点相关函数
  17. virtual void removeAllChildrenWithCleanup(bool bCleanup);
  18. virtual void reorderChild(CCNode *pChild,int zOrder);
  19. virtual void addChild(CCNode *pChild);
  20. virtual void addChild(CCNode *pChild,int zOrder);
  21. virtual void addChild(CCNode *pChild,int zOrder,int tag);
  22. virtual void sortAllChildren();
  23. virtual void setScale(float fScale); //设置缩放比例
  24. virtual void setVertexZ(float fVertexZ); //设置Z坐标
  25. virtual void setAnchorPoint(const CCPoint& anchor); //两个锚点相关函数
  26. virtual void ignoreAnchorPointForPosition(bool value);
  27. virtual void setVisible(bool bVisible); //设置是否可见
  28. virtual void draw(void); //绘制
  29. virtual void setColor(const ccColor3B& color3); //几个RGB颜色相关和显示相关函数
  30. virtual void updateDisplayedColor(const ccColor3B& parentColor);
  31. virtual void setOpacity(GLubyte opacity);
  32. virtual void setOpacityModifyRGB(bool modify);
  33. virtual bool isOpacityModifyRGB(void);
  34. virtual void updateDisplayedOpacity(GLubyte parentOpacity);
  35. virtual void updateTransform(void); //更新变换(旋转,缩放,平移)
  36. virtual CCSpriteBatchNode* getBatchNode(void); //获得和设置批处理节点对象
  37. virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
  38. virtual void setTextureRect(const CCRect& rect); //几个矩形设置相关函数
  39. virtual void setTextureRect(const CCRect& rect,bool rotated,const CCSize& untrimmedSize);
  40. virtual void setVertexRect(const CCRect& rect);
  41. virtual void setDisplayFrame(CCSpriteFrame *pNewFrame); //帧及动画相关函数
  42. virtual bool isFrameDisplayed(CCSpriteFrame *pFrame);
  43. virtual CCSpriteFrame* displayFrame(void);
  44. virtual void setDisplayFrameWithAnimationName(const char *animationName,int frameIndex);
  45. inline virtual bool isDirty(void) { return m_bDirty; } //淡入淡出
  46. inline virtual void setDirty(bool bDirty) { m_bDirty = bDirty; }
  47. inline ccV3F_C4B_T2F_Quad getQuad(void) { return m_sQuad; }
  48. inline bool isTextureRectRotated(void) { return m_bRectRotated; }
  49. inline unsigned int getAtlasIndex(void) { return m_uAtlasIndex; }
  50. inline void setAtlasIndex(unsigned int uAtlasIndex) { m_uAtlasIndex = uAtlasIndex; }
  51.  
  52. inline const CCRect& getTextureRect(void) { return m_obRect; } //获得纹理矩形
  53.  
  54. inline CCTextureAtlas* getTextureAtlas(void) { return m_pobTextureAtlas; }
  55. inline void setTextureAtlas(CCTextureAtlas *pobTextureAtlas) { m_pobTextureAtlas = pobTextureAtlas; }
  56.  
  57. inline const CCPoint& getOffsetPosition(void) { return m_obOffsetPosition; } //设置偏移位置
  58.  
  59. bool isFlipX(void); //翻转相关的函数
  60. void setFlipX(bool bFlipX);
  61. bool isFlipY(void);
  62. void setFlipY(bool bFlipY);
  63. protected:
  64. void updateColor(void);
  65. virtual void setTextureCoords(CCRect rect);
  66. virtual void updateBlendFunc(void);
  67. virtual void setReorderChildDirtyRecursively(void);
  68. virtual void setDirtyRecursively(bool bValue);
  69.  
  70. CCTextureAtlas* m_pobTextureAtlas;
  71. unsigned int m_uAtlasIndex;
  72. CCSpriteBatchNode* m_pobBatchNode;
  73. bool m_bDirty;
  74. bool m_bRecursiveDirty;
  75. bool m_bHasChildren;
  76. bool m_bShouldBeHidden;
  77. CCAffineTransform m_transformToBatch;
  78. ccBlendFunc m_sBlendFunc;
  79. CCTexture2D* m_pobTexture;
  80.  
  81. CCRect m_obRect;
  82. bool m_bRectRotated;
  83.  
  84. CCPoint m_obOffsetPosition;
  85. CCPoint m_obUnflippedOffsetPositionFromCenter;
  86.  
  87. ccV3F_C4B_T2F_Quad m_sQuad;
  88.  
  89. bool m_bOpacityModifyRGB;
  90.  
  91. bool m_bFlipX;
  92. bool m_bFlipY;
  93. };
3、CCTextureProtocol:纹理(协议)底层处理类,继承自CCBlendProtocol,很简单,只有两个函数,设置和获得纹理对象
  1. class CC_DLL CCTextureProtocol : public CCBlendProtocol
  2. {
  3. public:
  4. virtual CCTexture2D* getTexture(void) = 0;
  5. virtual void setTexture(CCTexture2D *texture) = 0;
  6. };
4、CCBlendProtocol:混合(协议)底层接口类,很简单,两函数分别是设置和获得混合对象
  1. class CC_DLL CCBlendProtocol
  2. {
  3. public:
  4. virtual void setBlendFunc(ccBlendFunc blendFunc) = 0;
  5. virtual ccBlendFunc getBlendFunc(void) = 0;
  6. };
5、CCGLBufferedNode:openGL缓冲节点类
  1. class CCGLBufferedNode
  2. {
  3. public:
  4. CCGLBufferedNode(void);
  5.  
  6. void setGLBufferData(void *buf,GLuint bufSize,int slot); //设置缓冲数据
  7. void setGLIndexData(void *buf,int slot);
  8.  
  9. #define BUFFER_SLOTS 4
  10. GLuint m_bufferObject[BUFFER_SLOTS];
  11. GLuint m_bufferSize[BUFFER_SLOTS];
  12.  
  13. GLuint m_indexBufferObject[BUFFER_SLOTS];
  14. GLuint m_indexBufferSize[BUFFER_SLOTS];
  15. };

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