axmol/cocos2dx/include/CCSpriteFrame.h

122 lines
4.4 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __SPRITE_CCSPRITE_FRAME_H__
#define __SPRITE_CCSPRITE_FRAME_H__
#include "CCNode.h"
#include "CCProtocols.h"
#include "CCObject.h"
2010-08-04 15:46:12 +08:00
namespace cocos2d {
class CCRect;
class CCPoint;
class CCSize;
class CCTexture2D;
class CCZone;
2010-09-28 18:27:33 +08:00
/** @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:
2010-09-29 17:39:45 +08:00
CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture, rect, offset);
sprite->setDisplayFrame(frame);
*/
class CC_DLL CCSpriteFrame : public CCObject
{
public:
// attributes
inline CCRect getRectInPixels(void) { return m_obRectInPixels; }
inline void setRectInPixels(CCRect rectInPixels) { m_obRectInPixels = rectInPixels; }
2010-12-27 10:26:56 +08:00
inline bool isRotated(void) { return m_bRotated; }
inline void setRotated(bool bRotated) { m_bRotated = bRotated; }
2010-09-28 16:18:05 +08:00
/** get rect of the frame */
inline CCRect getRect(void) { return m_obRect; }
2010-09-28 16:18:05 +08:00
/** set rect of the frame */
inline void setRect(CCRect rect) { m_obRect = rect; }
2010-09-28 16:18:05 +08:00
/** get offset of the frame */
inline CCPoint getOffsetInPixels(void) { return m_obOffsetInPixels; }
2010-09-28 16:18:05 +08:00
/** set offset of the frame */
inline void setOffsetInPixels(CCPoint offsetInPixels) { m_obOffsetInPixels = offsetInPixels; }
2010-09-28 16:18:05 +08:00
/** get original size of the trimmed image */
inline CCSize getOriginalSizeInPixels(void) { return m_obOriginalSizeInPixels; }
2010-09-28 16:18:05 +08:00
/** set original size of the trimmed image */
inline void setOriginalSizeInPixels(CCSize sizeInPixels) { m_obOriginalSizeInPixels = sizeInPixels; }
2010-09-28 16:18:05 +08:00
/** get texture of the frame */
inline CCTexture2D* getTexture(void) { return m_pobTexture; }
2010-09-28 16:18:05 +08:00
/** set texture of the frame, the texture is retained */
inline void setTexture(CCTexture2D* pobTexture)
{
CC_SAFE_RETAIN(pobTexture);
CC_SAFE_RELEASE(m_pobTexture);
m_pobTexture = pobTexture;
}
public:
2010-07-22 15:54:02 +08:00
~CCSpriteFrame(void);
virtual CCObject* copyWithZone(CCZone *pZone);
2010-07-22 15:54:02 +08:00
2010-12-27 10:26:56 +08:00
/** Create a CCSpriteFrame with a texture, rect in points.
It is assumed that the frame was not trimmed.
*/
static CCSpriteFrame* frameWithTexture(CCTexture2D* pobTexture, CCRect rect);
2010-12-27 10:26:56 +08:00
/** 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* frameWithTexture(CCTexture2D* pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize);
public:
2010-12-27 10:26:56 +08:00
/** Initializes a CCSpriteFrame with a texture, rect in points.
It is assumed that the frame was not trimmed.
*/
bool initWithTexture(CCTexture2D* pobTexture, CCRect rect);
2010-12-27 10:26:56 +08:00
/** 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, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize);
protected:
CCRect m_obRectInPixels;
2010-12-27 10:26:56 +08:00
bool m_bRotated;
CCRect m_obRect;
CCPoint m_obOffsetInPixels;
CCSize m_obOriginalSizeInPixels;
CCTexture2D *m_pobTexture;
};
2010-08-04 15:46:12 +08:00
}//namespace cocos2d
#endif //__SPRITE_CCSPRITE_FRAME_H__