cocos2d-x 动画详解之二CCSpriteBatchNode
CCSpriteBatchNode 原来是 CCSpritSheet
A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas).
CCSpriteBatchNode只包含一个图片或纹理对象
它的对象通过 texture2d 或 fileImage 生成。你可以理解为它是把一堆零散的图片整合到一张大图中的图片
它的绘制效率要高于你把这个图内的零散元素单个绘制
Public Member Functions |
|
~CCSpriteBatchNode () | |
CCTextureAtlas * | getTextureAtlas (void) 获取地图集 |
void | setTextureAtlas (CCTextureAtlas *textureAtlas) 设置地图集 |
CCArray * | getDescendants (void) 获取子节点 |
bool | initWithTexture (CCTexture2D *tex, unsigned int capacity) 初始化通过纹理 |
initializes a CCSpriteBatchNode with a texture2d and capacity of children. | |
bool | initWithFile (const char *fileImage, unsigned int capacity)初始化通过图片名 |
initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children. | |
void | increaseAtlasCapacity () 扩容 |
void | removeChildAtIndex (unsigned int index, bool doCleanup) |
removes a child given a certain index. | |
void | insertChild (CCSprite *child, unsigned int index) |
void | removeSpriteFromAtlas (CCSprite *sprite) |
unsigned int | rebuildIndexInOrder (CCSprite *parent, unsigned int index) |
unsigned int | highestAtlasIndexInChild (CCSprite *sprite) |
unsigned int | lowestAtlasIndexInChild (CCSprite *sprite) |
unsigned int | atlasIndexForChild (CCSprite *sprite, int z) |
virtual CCTexture2D * | getTexture (void) 获取纹理 |
virtual void | setTexture (CCTexture2D *texture) |
virtual void | setBlendFunc (ccBlendFunc blendFunc) |
virtual ccBlendFunc | getBlendFunc (void) |
virtual void | visit (void) |
recursive method that visit its children and draw them | |
virtual void | addChild (CCNode *child) |
Adds a child to the container with z-order as 0. | |
virtual void | addChild (CCNode *child, 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 *child, 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 | reorderChild (CCNode *child, int zOrder) |
Reorders a child according to a new z value. | |
virtual void | removeChild (CCNode *child, bool cleanup) |
Removes a child from the container. | |
virtual void | removeAllChildrenWithCleanup (bool cleanup) |
Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter. | |
virtual void | draw (void) |
Override this method to draw your own node. | |
Static Public Member Functions |
|
static CCSpriteBatchNode * | batchNodeWithTexture (CCTexture2D *tex) |
creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children. | |
static CCSpriteBatchNode * | batchNodeWithTexture (CCTexture2D *tex, unsigned int capacity) |
creates a CCSpriteBatchNode with a texture2d and capacity of children. | |
static CCSpriteBatchNode * | batchNodeWithFile (const char *fileImage) 默认29个孩子 |
creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children. | |
static CCSpriteBatchNode * | batchNodeWithFile (const char *fileImage, unsigned int capacity) |
creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children. | |
Protected Member Functions |
|
void | addQuadFromSprite (CCSprite *sprite, unsigned int index) |
CCSpriteBatchNode * | addSpriteWithoutQuad (CCSprite *child, unsigned int z, int aTag) |
Protected Attributes |
|
CCTextureAtlas * | m_pobTextureAtlas |
ccBlendFunc | m_blendFunc |
CCArray * | m_pobDescendants |
Detailed Description
CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call (often known as "batch draw").
CCSpriteBatchNode 象一个批节点[容器] 包含孩子,通过OpenGL绘制
A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas). Only the CCSprites that are contained in that texture can be added to theCCSpriteBatchNode. All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call. If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient.
Limitations:
- The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to aCCSpriteBatchNode. 只接受CCSprite 或者其子类
- Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture.