class CC_DLL CCSprite : public CCNodeRGBA, public CCTextureProtocol
{
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);
// 初始化精灵对象,2d纹理对象,纹理对象-矩形区域
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);
//设置纹理、获取纹理对象
virtual void setTexture(CCTexture2D *texture);
virtual CCTexture2D* getTexture(void);
// 设置混合对象、获取混合对象
inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; }
inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; }
// 设置x、y放缩系数
virtual void setScaleX(float fScaleX);
virtual void setScaleY(float fScaleY);
// 设置位置
virtual void setPosition(const CCPoint& pos);
// 设置旋转角度
virtual void setRotation(float fRotation);
// 设置x、y的旋转
virtual void setRotationX(float fRotationX);
virtual void setRotationY(float fRotationY);
// 设置x的扭曲,y的扭曲
virtual void setSkewX(float sx);
virtual void setSkewY(float sy);
// 移除孩子节点
virtual void removeChild(CCNode* pChild, bool bCleanup);
virtual void removeAllChildrenWithCleanup(bool bCleanup);
// 改变子节点的zorder值
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();
// 设置放缩xy共同的因子
virtual void setScale(float fScale);
// 设置节点z值
virtual void setVertexZ(float fVertexZ);
// 设置锚点,忽略锚点,设置节点可见性
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);
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);
// 设置批处理节点
// CCSpriteBatchNode *batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
// CCSprite *sprite = CCSprite::createWithTexture(batch->getTexture(), CCRectMake(0, 0, 57, 57));
// batch->addChild(sprite);
// layer->addChild(batch);
virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
// 设置纹理区域
virtual void setTextureRect(const CCRect& rect);
virtual void setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize);
// Sets the vertex rect.It will be called internally by setTextureRect
virtual void setVertexRect(const CCRect& rect);
// 设置精灵的显示帧
virtual void setDisplayFrame(CCSpriteFrame *pNewFrame);
// 查询一个精灵帧是否显示
virtual bool isFrameDisplayed(CCSpriteFrame *pFrame);
// 返回当前显示帧
virtual CCSpriteFrame* displayFrame(void);
// 改变显示帧,从CCAnimationCache指定的动画名和索引获取
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; }
// Gets the weak reference of the CCTextureAtlas when the sprite is rendered using via CCSpriteBatchNode
inline CCTextureAtlas* getTextureAtlas(void) { return m_pobTextureAtlas; }
// Sets the weak reference of the CCTextureAtlas when the sprite is rendered using via CCSpriteBatchNode
inline void setTextureAtlas(CCTextureAtlas *pobTextureAtlas) { m_pobTextureAtlas = pobTextureAtlas; }
// Gets the offset position of the sprite. Calculated automatically by editors like Zwoptex.
inline const CCPoint& getOffsetPosition(void) { return m_obOffsetPosition; }
// 查询精灵x方向是否偏转
bool isFlipX(void);
void setFlipX(bool bFlipX);
// 查询精灵y方向是否偏转
bool isFlipY(void);
void setFlipY(bool bFlipY);
protected:
CCTextureAtlas* m_pobTextureAtlas; /// CCSpriteBatchNode texture atlas (weak reference)
unsigned int m_uAtlasIndex; /// Absolute (real) Index on the SpriteSheet
CCSpriteBatchNode* m_pobBatchNode; /// Used batch node (weak reference)
bool m_bDirty; /// Whether the sprite needs to be updated
bool m_bRecursiveDirty; /// Whether all of the sprite's children needs to be updated
bool m_bHasChildren; /// Whether the sprite contains children
bool m_bShouldBeHidden; /// should not be drawn because one of the ancestors is not visible
CCAffineTransform m_transformToBatch;
ccBlendFunc m_sBlendFunc; /// It's required for CCTextureProtocol inheritance
CCTexture2D* m_pobTexture; /// CCTexture2D object that is used to render the sprite
CCRect m_obRect; /// Retangle of CCTexture2D
bool m_bRectRotated; /// Whether the texture is rotated
// Offset Position (used by Zwoptex)
CCPoint m_obOffsetPosition;
CCPoint m_obUnflippedOffsetPositionFromCenter;
// vertex coords, texture coords and color info
ccV3F_C4B_T2F_Quad m_sQuad;
// opacity and RGB protocol
bool m_bOpacityModifyRGB;
// image is flipped
bool m_bFlipX; /// Whether the sprite is flipped horizaontally or not.
bool m_bFlipY; /// Whether the sprite is flipped vertically or not.
};
CCSprite类
最新推荐文章于 2016-04-26 20:47:01 发布