CCSpriteBatchNode Class Reference
Inherits from | CCNode : NSObject |
Conforms to | CCTextureProtocol |
Declared in | CCSpriteBatchNode.h |
Overview
CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call (often known as “batch draw”).
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 the CCSpriteBatchNode. 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 a CCSpriteBatchNode. – 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.
Tasks
Other Methods
-
textureAtlas
returns the TextureAtlas that is used
property -
blendFunc
conforms to CCTextureProtocol protocol
property -
descendants
descendants (children, grandchildren, etc)
property -
+ batchNodeWithTexture:
creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children. The capacity will be increased in 33% in runtime if it run out of space.
-
+ batchNodeWithTexture:capacity:
creates a CCSpriteBatchNode with a texture2d and capacity of children. The capacity will be increased in 33% in runtime if it run out of space.
-
+ batchNodeWithFile:
creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr.
-
+ batchNodeWithFile:capacity:
creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr.
-
– initWithTexture:capacity:
initializes a CCSpriteBatchNode with a texture2d and capacity of children. The capacity will be increased in 33% in runtime if it run out of space.
-
– initWithFile:capacity:
initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr.
-
– increaseAtlasCapacity
-
– removeChildAtIndex:cleanup:
removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
-
– removeChild:cleanup:
removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
-
– insertChild:inAtlasAtIndex:
-
– appendChild:
-
– removeSpriteFromAtlas:
-
– rebuildIndexInOrder:atlasIndex:
-
– atlasIndexForChild:atZ:
-
– reorderBatch:
QuadExtensions Methods
-
– insertQuadFromSprite:quadIndex:
Inserts a quad at a certain index into the texture atlas. The CCSprite won’t be added into the children array. This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won’t be updated. For example: a tile map (CCTMXMap) or a label with lots of characters (CCLabelBMFont)
-
– updateQuadFromSprite:quadIndex:
Updates a quad at a certain index into the texture atlas. The CCSprite won’t be added into the children array. This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won’t be updated. For example: a tile map (CCTMXMap) or a label with lots of characters (CCLabelBMFont)
-
– addSpriteWithoutQuad:z:tag:
Properties
blendFunc
conforms to CCTextureProtocol protocol
@property (nonatomic, readwrite) ccBlendFunc blendFunc
Declared In
CCSpriteBatchNode.h
Class Methods
batchNodeWithFile:
creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr.
+ (id)batchNodeWithFile:(NSString *)fileImage
Declared In
CCSpriteBatchNode.h
batchNodeWithFile:capacity:
creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr.
+ (id)batchNodeWithFile:(NSString *)fileImage capacity:(NSUInteger)capacity
Declared In
CCSpriteBatchNode.h
Instance Methods
initWithFile:capacity:
initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr.
- (id)initWithFile:(NSString *)fileImage capacity:(NSUInteger)capacity
Declared In
CCSpriteBatchNode.h
initWithTexture:capacity:
initializes a CCSpriteBatchNode with a texture2d and capacity of children. The capacity will be increased in 33% in runtime if it run out of space.
- (id)initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity
Declared In
CCSpriteBatchNode.h
insertQuadFromSprite:quadIndex:
Inserts a quad at a certain index into the texture atlas. The CCSprite won’t be added into the children array. This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won’t be updated. For example: a tile map (CCTMXMap) or a label with lots of characters (CCLabelBMFont)
- (void)insertQuadFromSprite:(CCSprite *)sprite quadIndex:(NSUInteger)index
Declared In
CCSpriteBatchNode.h
removeChild:cleanup:
removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
- (void)removeChild:(CCSprite *)sprite cleanup:(BOOL)doCleanup
Discussion
Warning: Removing a child from a CCSpriteBatchNode is very slow
Declared In
CCSpriteBatchNode.h
removeChildAtIndex:cleanup:
removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
- (void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup
Discussion
Warning: Removing a child from a CCSpriteBatchNode is very slow
Declared In
CCSpriteBatchNode.h
updateQuadFromSprite:quadIndex:
Updates a quad at a certain index into the texture atlas. The CCSprite won’t be added into the children array. This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won’t be updated. For example: a tile map (CCTMXMap) or a label with lots of characters (CCLabelBMFont)
- (void)updateQuadFromSprite:(CCSprite *)sprite quadIndex:(NSUInteger)index
Declared In
CCSpriteBatchNode.h