#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;
/** @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);
{
m_obRectInPixels = rectInPixels;
m_obRect = CC_RECT_PIXELS_TO_POINTS(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);
{
m_obRect = rect;
m_obRectInPixels = CC_RECT_POINTS_TO_PIXELS(m_obRect);
}
//精灵帧的位置偏移(以像素值计算)
const CCPoint& getOffsetInPixels(void);
/** set offset of the frame */
void setOffsetInPixels(const CCPoint& offsetInPixels);
//修剪后图片的原始大小(以像素值计算)
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__