CCSpriteFrame

本文详细介绍了CCSpriteFrame类的功能、属性及其创建方法,包括如何设置纹理、矩形、偏移量和原始大小,以及如何通过指定文件名和矩形来创建精灵帧。此外,还提供了初始化方法的说明,帮助开发者更高效地使用该类进行CC Sprite的帧操作。

#ifndef __SPRITE_CCSPRITE_FRAME_H__

#define __SPRITE_CCSPRITE_FRAME_H__


#include "base_nodes/CCNode.h"

#include "CCProtocols.h"

#include "cocoa/CCObject.h"

#include "cocoa/CCGeometry.h"


NS_CC_BEGIN


class CCTexture2D;

class CCZone;


/**

 * @addtogroup sprite_nodes

 * @{

 */


/** @brief A CCSpriteFrame has:

    - texture: A CCTexture2D that will be used by the CCSprite

    - rectangle: A rectangle of the texture



 You can modify the frame of a CCSprite by doing:

 

    CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture, rect, offset);

    sprite->setDisplayFrame(frame);

 */

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:

    ~CCSpriteFrame(void);

    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, rect, rotated, offset and originalSize in pixels.

     The originalSize is the size in points of the frame before being trimmed.

     */

    static CCSpriteFrame* createWithTexture(CCTexture2D* pobTexture, const CCRect& rect, bool rotated, const CCPoint& offset, 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, rect, rotated, offset and originalSize in pixels.

    The originalSize is the size in points of the frame before being trimmed.

    */

    bool initWithTexture(CCTexture2D* pobTexture, const CCRect& rect, bool rotated, const CCPoint& offset, const CCSize& originalSize);


    /** Initializes a CCSpriteFrame with a texture, rect, rotated, 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 CCRect& rect, bool rotated, const CCPoint& offset, 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;

};


// end of sprite_nodes group

/// @}


NS_CC_END


#endif //__SPRITE_CCSPRITE_FRAME_H__


转载于:https://www.cnblogs.com/sssssnian/p/3748632.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值