Class cc.SpriteBatchNode

Class Summary
Constructor Attributes Constructor Name and Description
 

In Canvas render mode ,cc.SpriteBatchNodeCanvas is like a normal node: if it contains children.

Method Summary

Class Detail

cc.SpriteBatchNode()

In Canvas render mode ,cc.SpriteBatchNodeCanvas is like a normal node: if it contains children.
If its _useCache is set to true, it can cache the result that all children of SpriteBatchNode to a canvas
(often known as "batch draw").

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.

//create a SpriteBatchNode
var parent2 = cc.SpriteBatchNode.create("res/animations/grossini.png", 50);

Field Detail

{Array} descendants
- <@readonly> Descendants of sprite batch node
{cc.TextureAtlas} textureAtlas
- The texture atlas

Method Detail

  • addChild(child, zOrder, tag)
    Add child to cc.SpriteBatchNode (override addChild of cc.Node)
    Parameters:
    {cc.Sprite} child
    {Number} zOrder Optional
    {Number} tag Optional
  • {cc.SpriteBatchNode} addSpriteWithoutQuad(child, z, aTag)

    This is the opposite of "addQuadFromSprite.
    It add the sprite to the children and descendants array, but it doesn't update add it to the texture atlas

    Parameters:
    {cc.Sprite} child
    {Number} z
    zOrder
    {Number} aTag
    Returns:
    {cc.SpriteBatchNode}
  • appendChild(sprite)
    addChild helper, faster than insertChild
    Parameters:
    {cc.Sprite} sprite
  • {Number} atlasIndexForChild(sprite, nZ)
    get atlas index for child
    Parameters:
    {cc.Sprite} sprite
    {Number} nZ
    Returns:
    {Number}
  • <static> {cc.SpriteBatchNode} cc.SpriteBatchNode.create(fileImage, capacity)

    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.

    1.
    //create a SpriteBatchNode with image path
    var spriteBatchNode = cc.SpriteBatchNode.create("res/animations/grossini.png", 50);
    2.
    //create a SpriteBatchNode with texture
    var texture = cc.textureCache.addImage("res/animations/grossini.png");
    var spriteBatchNode = cc.SpriteBatchNode.create(texture,50);
    Parameters:
    {String|cc.Texture2D} fileImage
    {Number} capacity
    Returns:
    {cc.SpriteBatchNode}
  • ctor(fileImage)
    Constructor
    Parameters:
    {String} fileImage
  • draw()
    draw cc.SpriteBatchNode (override draw of cc.Node)
  • {cc.BlendFunc} getBlendFunc()
    returns the blending function used for the texture
    Returns:
    {cc.BlendFunc}
  • {Array} getDescendants()
    Return Descendants of cc.SpriteBatchNode
    Returns:
    {Array}
  • {cc.Texture2D|HTMLImageElement|HTMLCanvasElement} getTexture()
    Return texture of cc.SpriteBatchNode
    Returns:
    {cc.Texture2D|HTMLImageElement|HTMLCanvasElement}
  • {cc.TextureAtlas} getTextureAtlas()
    Return TextureAtlas of cc.SpriteBatchNode
    Returns:
    {cc.TextureAtlas}
  • {Number} highestAtlasIndexInChild(sprite)
    get highest atlas index in child
    Parameters:
    {cc.Sprite} sprite
    Returns:
    {Number}
  • increaseAtlasCapacity()
    increase Atlas Capacity
  • {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.

    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.

    Parameters:
    {String} fileImage
    {Number} capacity
    Returns:
    {Boolean}
  • {Boolean} initWithTexture(tex, 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.

    Parameters:
    {cc.Texture2D} tex
    {Number} capacity Optional
    Returns:
    {Boolean}
  • insertChild(sprite, index)
    add child helper
    Parameters:
    {cc.Sprite} sprite
    {Number} index
  • insertQuadFromSprite(sprite, index)

    Inserts a quad at a certain index into the texture atlas. The cc.Sprite won't be added into the children array.
    This method should be called only when you are dealing with very big AtlasSprite 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 (cc.LabelBMFont)

    Parameters:
    {cc.Sprite} sprite
    {Number} index
  • {Number} lowestAtlasIndexInChild(sprite)
    get lowest atlas index in child
    Parameters:
    {cc.Sprite} sprite
    Returns:
    {Number}
  • {Number} rebuildIndexInOrder(pobParent, index)
    rebuild index in order for child
    Parameters:
    {cc.Sprite} pobParent
    {Number} index
    Returns:
    {Number}
  • removeAllChildren(cleanup)

    Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
    (override removeAllChildren of cc.Node)

    Parameters:
    {Boolean} cleanup
  • removeChild(child, cleanup)
    remove child from cc.SpriteBatchNode (override removeChild of cc.Node)
    Parameters:
    {cc.Sprite} child
    cleanup
  • 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)
    remove sprite from TextureAtlas
    Parameters:
    {cc.Sprite} sprite
  • reorderBatch(reorder)
    Sprites use this to start sortChildren, don't call this manually
    Parameters:
    {Boolean} reorder
  • reorderChild(child, zOrder)
    (override reorderChild of cc.Node)
    Parameters:
    {cc.Sprite} child
    {Number} zOrder
  • setBlendFunc(src, dst)
    set the source blending function for the texture
    Parameters:
    {Number | cc.BlendFunc} src
    {Number} dst
  • setTexture(texture)
    Texture of cc.SpriteBatchNode setter
    Parameters:
    {cc.Texture2D} texture
  • setTextureAtlas(textureAtlas)
    TextureAtlas of cc.SpriteBatchNode setter
    Parameters:
    {cc.TextureAtlas} textureAtlas
  • 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
  • visit(ctx)
    Don't call visit on it's children ( override visit of cc.Node )
    Parameters:
    {CanvasRenderingContext2D} ctx