《不靠谱2.x》006.CCSprite上003 CCSpriteFrame

一、概述
CCSpriteFrame继承自CCObject。看了源码后感觉和CCTexture2D一样,不常直接使用、更多作为中间变量。源码如下:

class CC_DLL CCSpriteFrame : public CCObject
{
public:
    // attributes

    inline const CCRect& getRectInPixels(void) { return m_obRectInPixels; }
    void setRectInPixels(const CCRect& rectInPixels);

    inline bool isRotated(void) { return m_brotated; }
    inline void setRotated(bool brotated) { m_brotated = brotated; }

    /** get rect of the frame */
    inline const CCRect& getRect(void) { return m_obRect; }
    /** set rect of the frame */
    void setRect(const CCRect& rect);

    /** get offset of the frame */
    const CCPoint& getoffsetInPixels(void);
    /** set offset of the frame */
    void setoffsetInPixels(const CCPoint& offsetInPixels);

    /** get original size of the trimmed image */
    inline const CCSize& getoriginalSizeInPixels(void) { return m_obOriginalSizeInPixels; }
    /** set original size of the trimmed image */
    inline void setoriginalSizeInPixels(const CCSize& sizeInPixels) { m_obOriginalSizeInPixels = sizeInPixels; }

    /** get original size of the trimmed image */
    inline const CCSize& getoriginalSize(void) { return m_obOriginalSize; }
    /** set original size of the trimmed image */
    inline void setoriginalSize(const CCSize& sizeInPixels) { m_obOriginalSize = sizeInPixels; }

    /** get texture of the frame */
    CCTexture2D* getTexture(void);
    /** set texture of the frame,the texture is retained */
    void setTexture(CCTexture2D* pobTexture);

    const CCPoint& getoffset(void);
    void setoffset(const CCPoint& offsets);

public:
    /**
     *  @js NA
     *  @lua NA
     */
    ~CCSpriteFrame(void);
    /** *  @js NA *  @lua NA */
    virtual CCObject* copyWithZone(CCZone *pZone);

    /** Create a CCSpriteFrame with a texture filename,rect in points. It is assumed that the frame was not trimmed. */
    static CCSpriteFrame* create(const char* filename,const CCRect& rect);

    /** Create a CCSpriteFrame with a texture filename,rect,rotated,offset and originalSize in pixels. The originalSize is the size in pixels of the frame before being trimmed. */
    static CCSpriteFrame* create(const char* filename,const CCRect& rect,bool rotated,const CCPoint& offset,const CCSize& originalSize);

    /** Create a CCSpriteFrame with a texture,rect in points. It is assumed that the frame was not trimmed. */
    static CCSpriteFrame* createWithTexture(CCTexture2D* pobTexture,const CCRect& rect);

    /** Create a CCSpriteFrame with a texture,offset and originalSize in pixels. The originalSize is the size in points of the frame before being trimmed. */
    static CCSpriteFrame* createWithTexture(CCTexture2D* pobTexture,const CCSize& originalSize);

public:
    /** Initializes a CCSpriteFrame with a texture,rect in points.
     It is assumed that the frame was not trimmed.
     */
    bool initWithTexture(CCTexture2D* pobTexture,const CCRect& rect);

    /** Initializes a CCSpriteFrame with a texture filename,rect in points; It is assumed that the frame was not trimmed. */
    bool initWithTextureFilename(const char* filename,const CCRect& rect);

    /** Initializes a CCSpriteFrame with a texture,offset and originalSize in pixels. The originalSize is the size in points of the frame before being trimmed. */
    bool initWithTexture(CCTexture2D* pobTexture,const CCSize& originalSize);

    /** Initializes a CCSpriteFrame with a texture,offset and originalSize in pixels. The originalSize is the size in pixels of the frame before being trimmed.  @since v1.1 */
    bool initWithTextureFilename(const char* filename,const CCSize& originalSize);


protected:
    CCPoint m_obOffset;
    CCSize m_obOriginalSize;
    CCRect m_obRectInPixels;
    bool   m_brotated;
    CCRect m_obRect;
    CCPoint m_obOffsetInPixels;
    CCSize m_obOriginalSizeInPixels;
    CCTexture2D *m_pobTexture;
    std::string  m_strTextureFilename;
};

二、分析
1、CCSpriteFrame可通过:文件名、纹理、纹理文件名(不知道和前面的文件名有什么区别)生成
2、可以获取或设置这些属性的值:角度以及是否有角度偏转、矩形、大小、2D纹理、偏移

三、总结 1、可通过文件名、纹理、纹理文件生成CCSpriteFrame对象 2、不常直接使用,更多的作为中间变量

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...