Class cc.TextureAtlas
- Defined in: CCTextureAtlas.js
- Extends cc.Class
Constructor Attributes | Constructor Name and Description |
---|---|
A class that implements a Texture Atlas. |
Method Summary
Class Detail
A class that implements a Texture Atlas.
Supported features:
The atlas file can be a PNG, JPG.
Quads can be updated in runtime
Quads can be added in runtime
Quads can be removed in runtime
Quads can be re-ordered in runtime
The TextureAtlas capacity can be increased or decreased in runtime.
Field Detail
Method Detail
-
Creates a TextureAtlas with an filename and with an initial capacity for Quads.
The TextureAtlas capacity can be increased in runtime.1. //creates a TextureAtlas with filename var textureAtlas = cc.TextureAtlas.create("res/hello.png", 3); 2. //creates a TextureAtlas with texture var texture = cc.textureCache.addImage("hello.png"); var textureAtlas = cc.TextureAtlas.create(texture, 3);
- Parameters:
- {String|cc.Texture2D} fileName
- {Number} capacity
- Returns:
- {cc.TextureAtlas|Null}
-
{String} description()Description
- Returns:
- {String}
-
drawNumberOfQuads(n, start)
Draws n quads from an index (offset).
n + start can't be greater than the capacity of the atlas- Parameters:
- {Number} n
- {Number} start
-
drawQuads()Draws all the Atlas's Quads
-
fillWithEmptyQuadsFromIndex(index, amount)Ensures that after a realloc quads are still empty
Used internally by CCParticleBatchNode- Parameters:
- {Number} index
- {Number} amount
-
{Number} getCapacity()Quantity of quads that can be stored with the current texture atlas size
- Returns:
- {Number}
-
{Array} getQuads()Quads that are going to be rendered
- Returns:
- {Array}
-
{Image} getTexture()Texture of the texture atlas
- Returns:
- {Image}
-
{Number} getTotalQuads()Quantity of quads that are going to be drawn.
- Returns:
- {Number}
-
increaseTotalQuadsWith(amount)Used internally by CCParticleBatchNode
don't use this unless you know what you're doing- Parameters:
- {Number} amount
-
{Boolean} initWithFile(file, capacity)
Initializes a TextureAtlas with a filename and with a certain capacity for Quads.
The TextureAtlas capacity can be increased in runtime.
WARNING: Do not reinitialize the TextureAtlas because it will leak memory.//example var textureAtlas = new cc.TextureAtlas(); textureAtlas.initWithTexture("hello.png", 3);
- Parameters:
- {String} file
- {Number} capacity
- Returns:
- {Boolean}
-
{Boolean} initWithTexture(texture, capacity)
Initializes a TextureAtlas with a previously initialized Texture2D object, and
with an initial capacity for Quads.
The TextureAtlas capacity can be increased in runtime.
WARNING: Do not reinitialize the TextureAtlas because it will leak memory//example var texture = cc.textureCache.addImage("hello.png"); var textureAtlas = new cc.TextureAtlas(); textureAtlas.initWithTexture(texture, 3);
- Parameters:
- {Image} texture
- {Number} capacity
- Returns:
- {Boolean}
-
insertQuad(quad, index)
Inserts a Quad (texture, vertex and color) at a certain index
index must be between 0 and the atlas capacity - 1- Parameters:
- {cc.V2F_C4B_T2F_Quad} quad
- {Number} index
-
insertQuadFromIndex(fromIndex, newIndex)
Removes the quad that is located at a certain index and inserts it at a new index
This operation is faster than removing and inserting in a quad in 2 different steps- Parameters:
- {Number} fromIndex
- {Number} newIndex
-
insertQuads(quads, index, amount)
Inserts a c array of quads at a given index
index must be between 0 and the atlas capacity - 1
this method doesn't enlarge the array when amount + index > totalQuads
- Parameters:
- {Array} quads
- {Number} index
- {Number} amount
-
{boolean} isDirty()whether or not the array buffer of the VBO needs to be updated
- Returns:
- {boolean}
-
moveQuadsFromIndex(oldIndex, amount, newIndex)Moves an amount of quads from oldIndex at newIndex
- Parameters:
- {Number} oldIndex
- {Number} amount
- {Number} newIndex
-
removeAllQuads()
Removes all Quads.
The TextureAtlas capacity remains untouched. No memory is freed.
The total number of quads to be drawn will be 0 -
removeQuadAtIndex(index)
Removes a quad at a given index number.
The capacity remains the same, but the total number of quads to be drawn is reduced in 1- Parameters:
- {Number} index
-
{Boolean} resizeCapacity(newCapacity)
Resize the capacity of the CCTextureAtlas.
The new capacity can be lower or higher than the current one
It returns YES if the resize was successful.
If it fails to resize the capacity it will return NO with a new capacity of 0.
no used for js- Parameters:
- {Number} newCapacity
- Returns:
- {Boolean}
-
setDirty(dirty)specify if the array buffer of the VBO needs to be updated
- Parameters:
- {Boolean} dirty
-
setQuads(quads)
- Parameters:
- {Array} quads
-
setTexture(texture)
- Parameters:
- {Image} texture
-
updateQuad(quad, index)
Updates a Quad (texture, vertex and color) at a certain index
index must be between 0 and the atlas capacity - 1- Parameters:
- {cc.V2F_C4B_T2F_Quad} quad
- {Number} index