Class cc.SpriteBatchNode
- Defined in: CCSpriteBatchNode.js
- Extends cc.Node
Constructor Attributes | Constructor Name and Description |
---|---|
cc.SpriteBatchNode(fileImage)
A cc.SpriteBatchNode can reference one and only one texture (one image file, one texture atlas). |
Method Summary
Class Detail
A cc.SpriteBatchNode can reference one and only one texture (one image file, one texture atlas).
Only the cc.Sprites that are contained in that texture can be added to the cc.SpriteBatchNode.
All cc.Sprites added to a cc.SpriteBatchNode are drawn in one WebGL draw call.
If the cc.Sprites are not added to a cc.SpriteBatchNode then an WebGL 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 cc.Sprite or any subclass of cc.Sprite.
eg: particles, labels and layer can't be added to a cc.SpriteBatchNode.
- 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.
// 1. create a SpriteBatchNode with image path var spriteBatchNode = new cc.SpriteBatchNode("res/animations/grossini.png"); // 2. create a SpriteBatchNode with texture var texture = cc.textureCache.addImage("res/animations/grossini.png"); var spriteBatchNode = new cc.SpriteBatchNode(texture);
- Parameters:
- {String|cc.Texture2D} fileImage
Field Detail
Method Detail
-
addChild(child, zOrder, tag)Add child to the sprite batch node (override addChild of cc.Node)
- Parameters:
- {cc.Sprite} child
- {Number} zOrder Optional
- {Number} tag Optional
-
{cc.SpriteBatchNode} addSpriteWithoutQuad(child, z, aTag)
Same as addChild
- Parameters:
- {cc.Sprite} child
- {Number} z
- zOrder
- {Number} aTag
- Deprecated:
- since v3.12
- Returns:
- {cc.SpriteBatchNode}
-
appendChild(sprite)Add child at the end
- Parameters:
- {cc.Sprite} sprite
-
{Number} atlasIndexForChild(sprite)Returns index for child
- Parameters:
- {cc.Sprite} sprite
- Deprecated:
- since v3.12
- Returns:
- {Number}
-
creates a cc.SpriteBatchNodeCanvas with a file image (.png, .jpg 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.
- Parameters:
- {String|cc.Texture2D} fileImage
- Deprecated:
- since v3.0, please use new construction instead
- Returns:
- {cc.SpriteBatchNode}
- See:
- cc.SpriteBatchNode
-
<static> cc.SpriteBatchNode.createWithTexture()
- Deprecated:
- since v3.0, please use new construction instead
- See:
- cc.SpriteBatchNode
-
{cc.BlendFunc} getBlendFunc()Returns the blending function used for the texture
- Returns:
- {cc.BlendFunc}
-
{Array} getDescendants()Return Descendants of cc.SpriteBatchNode
- Deprecated:
- since v3.12
- Returns:
- {Array}
-
{cc.Texture2D} getTexture()Returns texture of the sprite batch node
- Returns:
- {cc.Texture2D}
-
{cc.TextureAtlas} getTextureAtlas()Return null, no texture atlas is used any more
- Deprecated:
- since v3.12
- Returns:
- {cc.TextureAtlas}
-
{Number} highestAtlasIndexInChild(sprite)Returns highest atlas index in child
- Parameters:
- {cc.Sprite} sprite
- Deprecated:
- since v3.12
- Returns:
- {Number}
-
increaseAtlasCapacity()Do nothing
- Deprecated:
- since v3.12
-
{Boolean} init(fileImage, capacity)
initializes a cc.SpriteBatchNode 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.
Please pass parameters to constructor to initialize the sprite batch node, do not call this function yourself.- Parameters:
- {String} fileImage
- {Number} capacity
- Returns:
- {Boolean}
-
{Boolean} initWithFile(fileImage, capacity)
Initializes a cc.SpriteBatchNode 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.
Please pass parameters to constructor to initialize the sprite batch node, do not call this function yourself.- Parameters:
- {String} fileImage
- {Number} capacity
- Returns:
- {Boolean}
-
{Boolean} initWithTexture(tex)Set the texture property
- Parameters:
- {cc.Texture2D} tex
- Returns:
- {Boolean}
-
insertChild(sprite, index)Same as addChild(sprite, index)
- Parameters:
- {cc.Sprite} sprite
- The child sprite
- {Number} index
- The insert index
- Deprecated:
- since v3.12
-
insertQuadFromSprite(sprite, index)
Same as addChild(sprite, index)
- Parameters:
- {cc.Sprite} sprite
- {Number} index
- Deprecated:
- since v3.12
-
{Number} lowestAtlasIndexInChild(sprite)Returns lowest atlas index in child
- Parameters:
- {cc.Sprite} sprite
- Deprecated:
- since v3.12
- Returns:
- {Number}
-
{Number} rebuildIndexInOrder(pobParent, index)Do nothing
- Parameters:
- {cc.Sprite} pobParent
- {Number} index
- Deprecated:
- since v3.12
- Returns:
- {Number}
-
removeChildAtIndex(index, doCleanup)Removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
- Parameters:
- {Number} index
- {Boolean} doCleanup
-
removeSpriteFromAtlas(sprite, cleanup)Same as removeChild
- Parameters:
- {cc.Sprite} sprite
- {Boolean} cleanup Optional, Default: true
- true if all running actions and callbacks on the child node will be cleanup, false otherwise.
- Deprecated:
- since v3.12
-
reorderBatch(reorder)Sprites use this to start sortChildren, don't call this manually
- Parameters:
- {Boolean} reorder
- Deprecated:
- since v3.12
-
setBlendFunc(src, dst)Sets the source and destination blending function for the texture
- Parameters:
- {Number | cc.BlendFunc} src
- {Number} dst
-
setTexture(texture)Sets the texture of the sprite batch node.
- Parameters:
- {cc.Texture2D} texture
-
setTextureAtlas(textureAtlas)TextureAtlas of cc.SpriteBatchNode setter
- Parameters:
- {cc.TextureAtlas} textureAtlas
- Deprecated:
- since v3.12
-
updateQuadFromSprite(sprite, index)
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 cc.Sprite won't be updated.
For example: a tile map (cc.TMXMap) or a label with lots of characters (BitmapFontAtlas)
- Parameters:
- {cc.Sprite} sprite
- {Number} index