struct transformValues_ 擁有如下幾個參數
CCPoint pos; // position x and y 位置
CCPoint scale; // scale x and y 放大縮小
float rotation; 旋轉
CCPoint skew; // skew x and y 傾斜
CCPoint ap; // anchor point in pixels 錨點
bool visible; 是否可見
Public Member Functions |
|
virtual GLubyte | getOpacity (void) |
getOpacity 獲取透明度 | |
virtual void | setOpacity (GLubyte var) |
setOpacity 設置透明度 | |
virtual const ccColor3B & | getColor (void) |
getColor 獲取顏色 | |
virtual void | setColor (const ccColor3B &var) |
setColor 設置顏色 | |
virtual void | draw (void) 繪製 可以覆蓋轉換爲自己的繪製方式 |
Override this method to draw your own node. | |
bool | isDirty (void) 精靈是否需要更新在自己所在在的位圖上 |
whether or not the Sprite needs to be updated in the Atlas | |
void | setDirty (bool bDirty) 設置是否需要更新 |
make the Sprite to be updated in the Atlas. | |
ccV3F_C4B_T2F_Quad | getQuad (void) 獲取文本位置 頂點位置 和顏色 |
get the quad (tex coords, vertex coords and color) information | |
bool | isTextureRectRotated (void) 是否旋轉 |
returns whether or not the texture rectangle is rotated | |
unsigned int | getAtlasIndex (void) 獲取所在圖片集ID |
Set the index used on the TextureAtlas. | |
void | setAtlasIndex (unsigned int uAtlasIndex) 設置說屬圖片集ID |
Set the index used on the TextureAtlas. | |
const CCRect & | getTextureRect (void) 返回精靈大小 |
returns the rect of the CCSprite in points | |
bool | isUsesBatchNode (void) 判斷精靈是否在 CCSpriteBatchNode 渲染 |
whether or not the Sprite is rendered using a CCSpriteBatchNode | |
void | setUsesSpriteBatchNode (bool bUsesSpriteBatchNode) 設置該精靈對象在 CCSpriteBatchNode 中被渲染 |
make the Sprite been rendered using a CCSpriteBatchNode | |
CCTextureAtlas * | getTextureAtlas (void) 獲取設置地圖紋理 |
void | setTextureAtlas (CCTextureAtlas *pobTextureAtlas) |
CCSpriteBatchNode * | getSpriteBatchNode (void) 設置和獲取一批精靈集 |
void | setSpriteBatchNode (CCSpriteBatchNode *pobSpriteBatchNode) |
ccHonorParentTransform | getHonorParentTransform (void) 是否根據其父的矩陣變化而改變 |
whether or not to transform according to its parent transformations. | |
void | setHonorParentTransform (ccHonorParentTransform eHonorParentTransform) |
whether or not to transform according to its parent transformations. | |
const CCPoint & | getOffsetPositionInPixels (void) 獲取便宜位置(象素) |
Get offset position of the sprite. | |
ccBlendFunc | getBlendFunc (void) 設置獲取混合方法 |
conforms to CCTextureProtocol protocol | |
void | setBlendFunc (ccBlendFunc blendFunc) |
conforms to CCTextureProtocol protocol | |
CCSprite (void) | |
virtual | ~CCSprite (void) |
virtual bool | init (void) |
virtual void | removeChild (CCNode *pChild, bool bCleanup) 移除孩子 是否清理action |
Removes a child from the container. | |
virtual void | removeAllChildrenWithCleanup (bool bCleanup) |
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter. | |
virtual void | reorderChild (CCNode *pChild, int zOrder) 移除孩子由zOrder決定 |
Reorders a child according to a new z value. | |
virtual void | addChild (CCNode *pChild) |
Adds a child to the container with z-order as 0. | |
virtual void | addChild (CCNode *pChild, int zOrder) |
Adds a child to the container with a z-order If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. | |
virtual void | addChild (CCNode *pChild, int zOrder, int tag) |
Adds a child to the container with z order and tag If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. | |
virtual void | setDirtyRecursively (bool bValue) |
virtual void | setPosition (const CCPoint &pos) 設置位置 |
setPosition | |
virtual void | setPositionInPixels (const CCPoint &pos) 設置位置(象素) |
setPositionInPixels | |
virtual void | setRotation (float fRotation) 設置旋轉 |
setRotation | |
virtual void | setSkewX (float sx) 設置傾斜XY |
setSkewX | |
virtual void | setSkewY (float sy) |
setSkewY | |
virtual void | setScaleX (float fScaleX) 設置放大縮小 |
setScaleX | |
virtual void | setScaleY (float fScaleY) |
setScaleY | |
virtual void | setScale (float fScale) |
The scale factor of the node. | |
virtual void | setVertexZ (float fVertexZ) 設置Z軸頂點座標 |
setVertexZ | |
virtual void | setAnchorPoint (const CCPoint &anchor) 設置錨點座標 |
setAnchorPoint | |
virtual void | setIsRelativeAnchorPoint (bool bRelative) 設置是否相對錨點座標 |
setIsRelativeAnchorPoint | |
virtual void | setIsVisible (bool bVisible) 設置是否可見 |
setIsVisible | |
void | setFlipX (bool bFlipX) 設置X翻轉Y翻轉 |
void | setFlipY (bool bFlipY) |
bool | isFlipX (void) |
whether or not the sprite is flipped horizontally. | |
bool | isFlipY (void) |
whether or not the sprite is flipped vertically. | |
void | updateColor (void) |
virtual void | setIsOpacityModifyRGB (bool bValue) 設置是否RGB透明修飾 |
opacity: conforms to CCRGBAProtocol protocol | |
virtual bool | getIsOpacityModifyRGB (void) |
returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity); | |
virtual void | setTexture (CCTexture2D *texture) 設置紋理 |
virtual CCTexture2D * | getTexture (void) |
bool | initWithTexture (CCTexture2D *pTexture) 初始化精靈精靈通過紋理 |
Initializes an sprite with a texture. | |
bool | initWithTexture (CCTexture2D *pTexture, const CCRect &rect) 初始化sprite通過紋理和矩形 |
Initializes an sprite with a texture and a rect. | |
bool | initWithSpriteFrame (CCSpriteFrame *pSpriteFrame)初始化精靈通過精靈幀 |
bool | initWithSpriteFrameName (const char *pszSpriteFrameName) |
Initializes an sprite with an sprite frame name. 初始化精靈通過一個精靈幀名稱 | |
bool | initWithFile (const char *pszFilename)初始化精靈通過一個圖片地址 |
Initializes an sprite with an image filename. | |
bool | initWithFile (const char *pszFilename, const CCRect &rect) |
Initializes an sprite with an image filename, and a rect. 初始化精靈通過一個圖片地址和矩形 | |
bool | initWithBatchNode (CCSpriteBatchNode *batchNode, const CCRect &rect)初始化精靈通過精靈集合和一個矩形 |
Initializes an sprite with an CCSpriteBatchNode and a rect in points. | |
bool | initWithBatchNodeRectInPixels (CCSpriteBatchNode *batchNode, const CCRect &rect) |
Initializes an sprite with an CCSpriteBatchNode and a rect in pixels. | |
void | updateTransform (void) 更新矩陣 |
updates the quad according the the rotation, position, scale values. | |
void | useSelfRender (void)使用自身渲染 |
tell the sprite to use self-render. | |
void | setTextureRect (const CCRect &rect)更新精靈在紋理上的矩形 |
updates the texture rect of the CCSprite in points. | |
void | setTextureRectInPixels (const CCRect &rect, bool rotated, const CCSize &size) |
updates the texture rect, rectRotated and untrimmed size of the CCSprite in pixels | |
void | useBatchNode (CCSpriteBatchNode *batchNode)使用精靈集 |
tell the sprite to use batch node render. | |
void | setDisplayFrame (CCSpriteFrame *pNewFrame)設置顯示幀 |
sets a new display frame to the CCSprite. | |
bool | isFrameDisplayed (CCSpriteFrame *pFrame)判斷當前顯示幀 |
returns whether or not a CCSpriteFrame is being displayed | |
CCSpriteFrame * | displayedFrame (void)返回當前顯示幀 |
returns the current displayed frame. | |
void | setDisplayFrameWithAnimationName (const char *animationName, int frameIndex) 設置動畫並設置顯示索引 |
changes the display frame with animation name and index. | |
Static Public Member Functions |
|
static CCSprite * | spriteWithTexture (CCTexture2D *pTexture) |
Creates an sprite with a texture. 通過紋理創建一個精靈 | |
static CCSprite * | spriteWithTexture (CCTexture2D *pTexture, const CCRect &rect) |
Creates an sprite with a texture and a rect. 通過紋理和矩形創建一個精靈 | |
static CCSprite * | spriteWithTexture (CCTexture2D *pTexture, const CCRect &rect, const CCPoint &offset) |
Creates an sprite with a texture, a rect and offset. 通過紋理和偏移矩形創建一個精靈 | |
static CCSprite * | spriteWithSpriteFrame (CCSpriteFrame *pSpriteFrame) |
Creates an sprite with an sprite frame. 通過幀創建一個精靈 | |
static CCSprite * | spriteWithSpriteFrameName (const char *pszSpriteFrameName) |
Creates an sprite with an sprite frame name. 通過幀名稱創建一個精靈 | |
static CCSprite * | spriteWithFile (const char *pszFileName) |
Creates an sprite with an image filename. 通過圖片創建一個精靈 | |
static CCSprite * | spriteWithFile (const char *pszFileName, const CCRect &rect) |
Creates an sprite with an image filename and a rect. 通過圖片和矩形創建一個精靈 | |
static CCSprite * | spriteWithBatchNode (CCSpriteBatchNode *batchNode, const CCRect &rect) |
Creates an sprite with an CCBatchNode and a rect. 通過精靈集和矩形創建一個精靈 | |
Protected Member Functions |
|
void | updateTextureCoords (const CCRect &rect) 更新紋理位置 矩形 |
void | updateBlendFunc (void) 更新混合方法 |
void | getTransformValues (struct transformValues_ *tv) 獲取矩陣參數 |
Protected Attributes |
|
GLubyte | m_nOpacity 透明 |
Opacity: conforms to CCRGBAProtocol protocol. | |
ccColor3B | m_sColor 顏色 |
Color: conforms with CCRGBAProtocol protocol. | |
CCTextureAtlas * | m_pobTextureAtlas 地圖集 |
unsigned int | m_uAtlasIndex 地圖集索引 |
CCSpriteBatchNode * | m_pobBatchNode 精靈集 |
ccHonorParentTransform | m_eHonorParentTransform 是否隨父矩陣變換 |
bool | m_bDirty 是否更新 |
bool | m_bRecursiveDirty ? |
bool | m_bHasChildren 是否有子對象 |
ccBlendFunc | m_sBlendFunc 是否混合方法 |
CCTexture2D * | m_pobTexture 紋理 |
bool | m_bUsesBatchNode 是否使用精靈集 |
CCRect | m_obRect 矩形 |
CCRect | m_obRectInPixels |
bool | m_bRectRotated 是否矩形旋轉 |
CCPoint | m_obOffsetPositionInPixels 偏移 |
CCPoint | m_obUnflippedOffsetPositionFromCenter |
ccV3F_C4B_T2F_Quad | m_sQuad QUAD |
ccColor3B | m_sColorUnmodified 原始顏色 |
bool | m_bOpacityModifyRGB 是否透明修飾 |
bool | m_bFlipX 是否X翻轉 |
bool | m_bFlipY 是否Y翻轉 |
Detailed Description 細節描述
CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
精靈是一個2D圖象
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
如果其父或者祖先是CCSpriteBatchNode 那麼遵循以下特徵和限制
- 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.
- 當其父爲一個CCBatchNode 尤其是 CCSpriteBatchNode 擁有多個孩子,它擁有更快的繪製速度。所有的孩子將一次性繪製。
- 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.Alias/Antialias
- 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.
//============================================================================
bool isFlipX | ( | void | ) |
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);
bool isFlipY | ( | void | ) |
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);
void setDisplayFrameWithAnimationName | ( | const char * | animationName, |
int | frameIndex | ||
) |
changes the display frame with animation name and index.
The animation name will be get from the CCAnimationCache
- Since:
- v0.99.5
void setFlipX | ( | bool | bFlipX | ) |
void setFlipY | ( | bool | bFlipY | ) |
void setHonorParentTransform | ( | ccHonorParentTransform | eHonorParentTransform | ) |
[inline] |
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.
- //創建竟ling==================================================================================
static CCSprite* spriteWithBatchNode | ( | CCSpriteBatchNode * | batchNode, |
const CCRect & | rect | ||
) |
[static] |
Creates an sprite with an CCBatchNode and a rect.
Creates an sprite with an image filename and a rect.
The offset will be (0,0).
static CCSprite* spriteWithFile | ( | const char * | pszFileName | ) |
[static] |
Creates an sprite with an image filename.
The rect used will be the size of the image. The offset will be (0,0).
static CCSprite* spriteWithSpriteFrame | ( | CCSpriteFrame * | pSpriteFrame | ) |
[static] |
Creates an sprite with an sprite frame.
static CCSprite* spriteWithSpriteFrameName | ( | const char * | pszSpriteFrameName | ) |
[static] |
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
static CCSprite* spriteWithTexture | ( | CCTexture2D * | pTexture | ) |
[static] |
Creates an sprite with a texture.
The rect used will be the size of the texture. The offset will be (0,0).
static CCSprite* spriteWithTexture | ( | CCTexture2D * | pTexture, |
const CCRect & | rect, | ||
const CCPoint & | offset | ||
) |
[static] |
Creates an sprite with a texture, a rect and offset.
static CCSprite* spriteWithTexture | ( | CCTexture2D * | pTexture, |
const CCRect & | rect | ||
) |
[static] |
Creates an sprite with a texture and a rect.
The offset will be (0,0).