2010-07-22 09:39:15 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
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 __SPITE_NODE_CCSPRITE_H__
|
|
|
|
#define __SPITE_NODE_CCSPRITE_H__
|
|
|
|
|
|
|
|
#include "CCNode.h"
|
|
|
|
#include "CCProtocols.h"
|
|
|
|
#include "CCTextureAtlas.h"
|
|
|
|
#include "ccTypes.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCMutableDictionary.h"
|
2010-07-22 14:52:35 +08:00
|
|
|
|
|
|
|
#include <string>
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
class CCSpriteBatchNode;
|
2010-07-22 09:39:15 +08:00
|
|
|
class CCSpriteSheet;
|
2010-12-27 10:26:56 +08:00
|
|
|
class CCSpriteSheetInternalOnly;
|
2010-07-22 09:39:15 +08:00
|
|
|
class CCSpriteFrame;
|
|
|
|
class CCAnimation;
|
2011-03-07 17:11:57 +08:00
|
|
|
class CCRect;
|
|
|
|
class CCPoint;
|
|
|
|
class CCSize;
|
2010-07-22 09:39:15 +08:00
|
|
|
class CCTexture2D;
|
|
|
|
struct transformValues_;
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
enum {
|
2010-12-27 10:26:56 +08:00
|
|
|
/// CCSprite invalid index on the CCSpriteBatchNode
|
2010-08-02 10:58:00 +08:00
|
|
|
CCSpriteIndexNotInitialized = 0xffffffff,
|
2010-07-22 09:39:15 +08:00
|
|
|
};
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/**
|
|
|
|
Whether or not an CCSprite will rotate, scale or translate with it's parent.
|
|
|
|
Useful in health bars, when you want that the health bar translates with it's parent but you don't
|
|
|
|
want it to rotate with its parent.
|
|
|
|
@since v0.99.0
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
//! Translate with it's parent
|
|
|
|
CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0,
|
|
|
|
//! Rotate with it's parent
|
|
|
|
CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1,
|
|
|
|
//! Scale with it's parent
|
|
|
|
CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2,
|
|
|
|
|
|
|
|
//! All possible transformation enabled. Default value.
|
|
|
|
CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE,
|
|
|
|
|
2010-07-22 09:39:15 +08:00
|
|
|
} ccHonorParentTransform;
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
|
|
|
|
*
|
|
|
|
* CCSprite can be created with an image, or with a sub-rectangle of an image.
|
|
|
|
*
|
|
|
|
* If the parent or any of its ancestors is a CCSpriteBatchNode then the following features/limitations are valid
|
|
|
|
* - Features when the parent is a CCBatchNode:
|
|
|
|
* - MUCH faster rendering, specially if the CCSpriteBatchNode has many children. All the children will be drawn in a single batch.
|
|
|
|
*
|
|
|
|
* - Limitations
|
|
|
|
* - Camera is not supported yet (eg: CCOrbitCamera action doesn't work)
|
|
|
|
* - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl)
|
|
|
|
* - The Alias/Antialias property belongs to CCSpriteBatchNode, so you can't individually set the aliased property.
|
|
|
|
* - The Blending function property belongs to CCSpriteBatchNode, so you can't individually set the blending function property.
|
|
|
|
* - Parallax scroller is not supported, but can be simulated with a "proxy" sprite.
|
|
|
|
*
|
|
|
|
* If the parent is an standard CCNode, then CCSprite behaves like any other CCNode:
|
|
|
|
* - It supports blending functions
|
|
|
|
* - It supports aliasing / antialiasing
|
|
|
|
* - But the rendering will be slower: 1 draw per children.
|
|
|
|
*
|
|
|
|
* The default anchorPoint in CCSprite is (0.5, 0.5).
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCSprite : public CCNode, public CCTextureProtocol, public CCRGBAProtocol
|
2010-07-22 09:39:15 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void draw(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// attributes
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** whether or not the Sprite needs to be updated in the Atlas */
|
2010-07-22 09:39:15 +08:00
|
|
|
inline bool isDirty(void) { return m_bDirty; }
|
2010-09-29 17:39:45 +08:00
|
|
|
/** make the Sprite to be updated in the Atlas. */
|
2010-07-22 09:39:15 +08:00
|
|
|
inline void setDirty(bool bDirty) { m_bDirty = bDirty; }
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** get the quad (tex coords, vertex coords and color) information */
|
2010-07-22 09:39:15 +08:00
|
|
|
inline ccV3F_C4B_T2F_Quad getQuad(void) { return m_sQuad; }
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
/** returns whether or not the texture rectangle is rotated */
|
2011-03-25 09:48:43 +08:00
|
|
|
inline bool isTextureRectRotated(void) { return m_bRectRotated; }
|
2010-09-29 17:39:45 +08:00
|
|
|
|
|
|
|
/** Set the index used on the TextureAtlas. */
|
2010-08-02 10:58:00 +08:00
|
|
|
inline unsigned int getAtlasIndex(void) { return m_uAtlasIndex; }
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Set the index used on the TextureAtlas.
|
|
|
|
@warning Don't modify this value unless you know what you are doing
|
|
|
|
*/
|
2010-08-02 10:58:00 +08:00
|
|
|
inline void setAtlasIndex(unsigned int uAtlasIndex) { m_uAtlasIndex = uAtlasIndex; }
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** returns the rect of the CCSprite in points */
|
2011-03-07 17:11:57 +08:00
|
|
|
inline CCRect getTextureRect(void) { return m_obRect; }
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** whether or not the Sprite is rendered using a CCSpriteBatchNode */
|
|
|
|
inline bool isUsesBatchNode(void) { return m_bUsesBatchNode; }
|
|
|
|
/** make the Sprite been rendered using a CCSpriteBatchNode */
|
|
|
|
inline void setUsesSpriteBatchNode(bool bUsesSpriteBatchNode) { m_bUsesBatchNode = bUsesSpriteBatchNode; }
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
inline CCTextureAtlas* getTextureAtlas(void) { return m_pobTextureAtlas; }
|
|
|
|
inline void setTextureAtlas(CCTextureAtlas *pobTextureAtlas) { m_pobTextureAtlas = pobTextureAtlas; }
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
inline CCSpriteBatchNode* getSpriteBatchNode(void) { return m_pobBatchNode; }
|
|
|
|
inline void setSpriteBatchNode(CCSpriteBatchNode *pobSpriteBatchNode) { m_pobBatchNode = pobSpriteBatchNode; }
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** whether or not to transform according to its parent transformations.
|
2010-08-02 10:58:00 +08:00
|
|
|
Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates.
|
|
|
|
IMPORTANT: Only valid if it is rendered using an CCSpriteSheet.
|
|
|
|
@since v0.99.0
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
inline ccHonorParentTransform getHornorParentTransform(void) { return m_eHonorParentTransform; }
|
2010-09-29 17:39:45 +08:00
|
|
|
/** whether or not to transform according to its parent transformations.
|
|
|
|
Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates.
|
|
|
|
IMPORTANT: Only valid if it is rendered using an CCSpriteSheet.
|
|
|
|
@since v0.99.0
|
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
inline void setHornorParentTransform(ccHonorParentTransform eHonorParentTransform) { m_eHonorParentTransform = eHonorParentTransform; }
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Get offset position of the sprite. Calculated automatically by editors like Zwoptex.
|
2010-08-02 10:58:00 +08:00
|
|
|
@since v0.99.0
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
inline CCPoint getOffsetPositionInPixels(void) { return m_obOffsetPositionInPixels; }
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** conforms to CCTextureProtocol protocol */
|
2010-07-22 09:39:15 +08:00
|
|
|
inline ccBlendFunc getBlendFunc(void) { return m_sBlendFunc; }
|
2010-09-28 16:18:05 +08:00
|
|
|
/** conforms to CCTextureProtocol protocol */
|
2010-07-22 09:39:15 +08:00
|
|
|
inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; }
|
|
|
|
|
|
|
|
public:
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Creates an sprite with a texture.
|
|
|
|
The rect used will be the size of the texture.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
|
|
|
static CCSprite* spriteWithTexture(CCTexture2D *pTexture);
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Creates an sprite with a texture and a rect.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
static CCSprite* spriteWithTexture(CCTexture2D *pTexture, CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** Creates an sprite with a texture, a rect and offset. */
|
2011-03-07 17:11:57 +08:00
|
|
|
static CCSprite* spriteWithTexture(CCTexture2D *pTexture, CCRect rect, CCPoint offset);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** Creates an sprite with an sprite frame. */
|
2010-07-22 09:39:15 +08:00
|
|
|
static CCSprite* spriteWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Creates an sprite with an sprite frame name.
|
|
|
|
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
|
|
|
If the CCSpriteFrame doesn't exist it will raise an exception.
|
|
|
|
@since v0.9
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
static CCSprite* spriteWithSpriteFrameName(const char *pszSpriteFrameName);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Creates an sprite with an image filename.
|
|
|
|
The rect used will be the size of the image.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
static CCSprite* spriteWithFile(const char *pszFileName);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Creates an sprite with an image filename and a rect.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
static CCSprite* spriteWithFile(const char *pszFileName, CCRect rect);
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
/** Creates an sprite with an CCBatchNode and a rect
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
static CCSprite* spriteWithBatchNode(CCSpriteBatchNode *batchNode, CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
static CCSprite* spriteWithSpriteSheet(CCSpriteSheetInternalOnly *pSpriteSheet, CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
public:
|
2010-09-04 12:02:52 +08:00
|
|
|
bool init(void);
|
2010-07-22 09:39:15 +08:00
|
|
|
virtual ~CCSprite(void);
|
2010-09-09 10:17:38 +08:00
|
|
|
CCSprite();
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
virtual void removeChild(CCNode* pChild, bool bCleanup);
|
|
|
|
virtual void removeAllChildrenWithCleanup(bool bCleanup);
|
2010-08-02 10:58:00 +08:00
|
|
|
virtual void reorderChild(CCNode *pChild, int zOrder);
|
2010-12-27 10:26:56 +08:00
|
|
|
virtual void addChild(CCNode *pChild);
|
|
|
|
virtual void addChild(CCNode *pChild, int zOrder);
|
|
|
|
virtual void addChild(CCNode *pChild, int zOrder, int tag);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
virtual void setDirtyRecursively(bool bValue);
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual void setPosition(CCPoint pos);
|
|
|
|
virtual void setPositionInPixels(CCPoint pos);
|
2010-07-22 09:39:15 +08:00
|
|
|
virtual void setRotation(float fRotation);
|
|
|
|
virtual void setScaleX(float fScaleX);
|
|
|
|
virtual void setScaleY(float fScaleY);
|
|
|
|
virtual void setScale(float fScale);
|
|
|
|
virtual void setVertexZ(float fVertexZ);
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual void setAnchorPoint(CCPoint anchor);
|
2010-07-22 09:39:15 +08:00
|
|
|
virtual void setIsRelativeAnchorPoint(bool bRelative);
|
|
|
|
virtual void setIsVisible(bool bVisible);
|
2010-07-22 14:52:35 +08:00
|
|
|
void setFlipX(bool bFlipX);
|
|
|
|
void setFlipY(bool bFlipY);
|
2011-03-25 09:48:43 +08:00
|
|
|
/** whether or not the sprite is flipped horizontally.
|
|
|
|
It only flips the texture of the sprite, and not the texture of the sprite's children.
|
|
|
|
Also, flipping the texture doesn't alter the anchorPoint.
|
|
|
|
If you want to flip the anchorPoint too, and/or to flip the children too use:
|
|
|
|
|
|
|
|
sprite->setScaleX(sprite->getScaleX() * -1);
|
2010-09-28 16:18:05 +08:00
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
bool isFlipX(void);
|
2011-03-25 09:48:43 +08:00
|
|
|
/** whether or not the sprite is flipped vertically.
|
|
|
|
It only flips the texture of the sprite, and not the texture of the sprite's children.
|
|
|
|
Also, flipping the texture doesn't alter the anchorPoint.
|
|
|
|
If you want to flip the anchorPoint too, and/or to flip the children too use:
|
|
|
|
|
|
|
|
sprite->setScaleY(sprite->getScaleY() * -1);
|
2010-09-28 16:18:05 +08:00
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
bool isFlipY(void);
|
|
|
|
|
|
|
|
void updateColor(void);
|
|
|
|
// RGBAProtocol
|
2010-09-28 16:18:05 +08:00
|
|
|
/** opacity: conforms to CCRGBAProtocol protocol */
|
2010-07-22 14:52:35 +08:00
|
|
|
virtual GLubyte getOpacity(void);
|
|
|
|
virtual void setOpacity(GLubyte opacity);
|
2010-09-28 16:18:05 +08:00
|
|
|
/** RGB colors: conforms to CCRGBAProtocol protocol */
|
2010-07-22 14:52:35 +08:00
|
|
|
virtual ccColor3B getColor(void);
|
|
|
|
virtual void setColor(ccColor3B color3);
|
|
|
|
virtual void setIsOpacityModifyRGB(bool bValue);
|
|
|
|
virtual bool getIsOpacityModifyRGB(void);
|
|
|
|
|
2010-08-31 11:20:37 +08:00
|
|
|
virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol *)this; }
|
|
|
|
|
2010-07-22 14:52:35 +08:00
|
|
|
// CCTextureProtocol
|
|
|
|
virtual void setTexture(CCTexture2D *texture);
|
|
|
|
virtual CCTexture2D* getTexture(void);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Initializes an sprite with a texture.
|
|
|
|
The rect used will be the size of the texture.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithTexture(CCTexture2D *pTexture);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Initializes an sprite with a texture and a rect.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
bool initWithTexture(CCTexture2D *pTexture, CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
// Initializes an sprite with an sprite frame.
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Initializes an sprite with an sprite frame name.
|
|
|
|
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
|
|
|
If the CCSpriteFrame doesn't exist it will raise an exception.
|
|
|
|
@since v0.9
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithSpriteFrameName(const char *pszSpriteFrameName);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Initializes an sprite with an image filename.
|
|
|
|
The rect used will be the size of the image.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithFile(const char *pszFilename);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** Initializes an sprite with an image filename, and a rect.
|
|
|
|
The offset will be (0,0).
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
bool initWithFile(const char *pszFilename, CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Initializes an sprite with an CCSpriteSheet and a rect in points */
|
2011-03-07 17:11:57 +08:00
|
|
|
bool initWithBatchNode(CCSpriteBatchNode *batchNode, CCRect rect);
|
|
|
|
bool initWithSpriteSheet(CCSpriteSheetInternalOnly *pSpriteSheet, CCRect rect);
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
/** Initializes an sprite with an CCSpriteSheet and a rect in pixels
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
bool initWithBatchNodeRectInPixels(CCSpriteBatchNode *batchNode, CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
// BatchNode methods
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** updates the quad according the the rotation, position, scale values. */
|
2010-07-22 09:39:15 +08:00
|
|
|
void updateTransform(void);
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
/** tell the sprite to use self-render.
|
|
|
|
@since v0.99.0
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
|
|
|
void useSelfRender(void);
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** updates the texture rect of the CCSprite in points. */
|
2011-03-07 17:11:57 +08:00
|
|
|
void setTextureRect(CCRect rect);
|
2010-07-22 14:52:35 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** updates the texture rect, rectRotated and untrimmed size of the CCSprite in pixels
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
void setTextureRectInPixels(CCRect rect, bool rotated, CCSize size);
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
/** tell the sprite to use batch node render.
|
2010-08-02 10:58:00 +08:00
|
|
|
@since v0.99.0
|
2010-07-22 09:39:15 +08:00
|
|
|
*/
|
2010-12-27 10:26:56 +08:00
|
|
|
void useBatchNode(CCSpriteBatchNode *batchNode);
|
|
|
|
void useSpriteSheetRender(CCSpriteSheetInternalOnly *pSpriteSheet);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
// Frames
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** sets a new display frame to the CCSprite. */
|
2010-07-22 09:39:15 +08:00
|
|
|
void setDisplayFrame(CCSpriteFrame *pNewFrame);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** returns whether or not a CCSpriteFrame is being displayed */
|
2010-07-22 09:39:15 +08:00
|
|
|
bool isFrameDisplayed(CCSpriteFrame *pFrame);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** returns the current displayed frame. */
|
2010-07-22 14:52:35 +08:00
|
|
|
CCSpriteFrame* displayedFrame(void);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** adds an Animation to the Sprite.
|
|
|
|
|
|
|
|
@deprecated Use CCAnimationCache instead. Will be removed in 1.0.1
|
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
void addAnimation(CCAnimation *pAnimation);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** returns an Animation given it's name.
|
|
|
|
|
|
|
|
@deprecated Use CCAnimationCache instead. Will be removed in 1.0.1
|
|
|
|
*/
|
2010-07-22 14:52:35 +08:00
|
|
|
CCAnimation* animationByName(const char *pszAnimationName);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-07-22 14:52:35 +08:00
|
|
|
// Animation
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** changes the display frame based on an animation and an index.
|
|
|
|
@deprecated Will be removed in 1.0.1. Use setDisplayFrameWithAnimationName:index instead
|
|
|
|
*/
|
2010-08-02 10:58:00 +08:00
|
|
|
void setDisplayFrame(const char *pszAnimationName, int nFrameIndex);
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** changes the display frame with animation name and index.
|
|
|
|
The animation name will be get from the CCAnimationCache
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
|
|
|
void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
|
|
|
|
|
2010-07-22 09:39:15 +08:00
|
|
|
protected:
|
2011-03-07 17:11:57 +08:00
|
|
|
void updateTextureCoords(CCRect rect);
|
2010-07-22 09:39:15 +08:00
|
|
|
void updateBlendFunc(void);
|
|
|
|
void initAnimationDictionary(void);
|
2010-12-27 10:26:56 +08:00
|
|
|
void getTransformValues(struct transformValues_ *tv); // optimization
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
protected:
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// Data used when the sprite is rendered using a CCSpriteSheet
|
2010-07-22 09:39:15 +08:00
|
|
|
//
|
|
|
|
CCTextureAtlas *m_pobTextureAtlas; // Sprite Sheet texture atlas (weak reference)
|
2010-09-24 18:10:32 +08:00
|
|
|
unsigned int m_uAtlasIndex; // Absolute (real) Index on the SpriteSheet
|
2010-12-27 10:26:56 +08:00
|
|
|
CCSpriteBatchNode *m_pobBatchNode; // Used batch node (weak reference)
|
2010-07-22 09:39:15 +08:00
|
|
|
ccHonorParentTransform m_eHonorParentTransform;// whether or not to transform according to its parent transformations
|
|
|
|
bool m_bDirty; // Sprite needs to be updated
|
|
|
|
bool m_bRecursiveDirty; // Subchildren needs to be updated
|
|
|
|
bool m_bHasChildren; // optimization to check if it contain children
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// Data used when the sprite is self-rendered
|
2010-07-22 09:39:15 +08:00
|
|
|
//
|
|
|
|
ccBlendFunc m_sBlendFunc; // Needed for the texture protocol
|
|
|
|
CCTexture2D *m_pobTexture;// Texture used to render the sprite
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// Shared data
|
2010-07-22 09:39:15 +08:00
|
|
|
//
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
// whether or not it's parent is a CCSpriteBatchNode
|
|
|
|
bool m_bUsesBatchNode;
|
2010-07-22 09:39:15 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
// texture
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect m_obRect;
|
|
|
|
CCRect m_obRectInPixels;
|
2010-12-27 10:26:56 +08:00
|
|
|
bool m_bRectRotated;
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
// Offset Position (used by Zwoptex)
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint m_obOffsetPositionInPixels; // absolute
|
|
|
|
CCPoint m_obUnflippedOffsetPositionFromCenter;
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
// vertex coords, texture coords and color info
|
|
|
|
ccV3F_C4B_T2F_Quad m_sQuad;
|
|
|
|
|
|
|
|
// opacity and RGB protocol
|
|
|
|
GLubyte m_nOpacity;
|
|
|
|
ccColor3B m_sColor;
|
|
|
|
ccColor3B m_sColorUnmodified;
|
|
|
|
bool m_bOpacityModifyRGB;
|
|
|
|
|
|
|
|
// image is flipped
|
|
|
|
bool m_bFlipX;
|
|
|
|
bool m_bFlipY;
|
|
|
|
|
|
|
|
// Animations that belong to the sprite
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableDictionary<std::string, CCAnimation*> *m_pAnimations;
|
2010-07-22 09:39:15 +08:00
|
|
|
};
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|
2010-07-22 09:39:15 +08:00
|
|
|
|
|
|
|
#endif // __SPITE_NODE_CCSPRITE_H__
|