Cocos Creator API

1.3.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

TextureAtlas

: cc

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.

dirty Boolean

Indicates whether or not the array buffer of the VBO needs to be updated.

texture Image

Image texture for cc.TextureAtlas.

capacity Number readOnly

Quantity of quads that can be stored with the current texture atlas size.

totalQuads Number readOnly

Quantity of quads that are going to be drawn.

quads Array readOnly

Quads that are going to be rendered.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

TextureAtlas
(
  • fileName
  • capacity
)

Creates a TextureAtlas with an filename and with an initial capacity for Quads.
The TextureAtlas capacity can be increased in runtime.

Constructor of cc.TextureAtlas

fileName String | Texture2D
capacity Number

:

--------------------------
1. //creates a TextureAtlas with  filename
var textureAtlas = new cc.TextureAtlas("res/hello.png", 3);

2. //creates a TextureAtlas with texture
var texture = cc.textureCache.addImage("hello.png");
var textureAtlas = new cc.TextureAtlas(texture, 3);

getTotalQuads ( ) Number

Quantity of quads that are going to be drawn.

:

: Number

getCapacity ( ) Number

Quantity of quads that can be stored with the current texture atlas size.

:

: Number

getTexture ( ) Image

Texture of the texture atlas.

:

: Image

setTexture
(
  • texture
)

Set texture for texture atlas.

texture Image

setDirty
(
  • dirty
)

specify if the array buffer of the VBO needs to be updated.

dirty Boolean

isDirty ( ) Boolean

whether or not the array buffer of the VBO needs to be updated.

:

getQuads ( ) Array

Quads that are going to be rendered.

:

: Array

setQuads
(
  • quads
)

quads Array

initWithFile
(
  • file
  • capacity
)
Boolean

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.

file String
capacity Number

:

:

--------------------------------------------------
var textureAtlas = new cc.TextureAtlas();
textureAtlas.initWithTexture("hello.png", 3);

initWithTexture
(
  • texture
  • capacity
)
Boolean

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

texture Image
capacity Number

:

:

---------------------------
var texture = cc.textureCache.addImage("hello.png");
var textureAtlas = new cc.TextureAtlas();
textureAtlas.initWithTexture(texture, 3);

updateQuad
(
  • quad
  • index
)

Updates a Quad (texture, vertex and color) at a certain index
index must be between 0 and the atlas capacity - 1

insertQuad
(
  • quad
  • index
)

Inserts a Quad (texture, vertex and color) at a certain index
index must be between 0 and the atlas capacity - 1

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

quads Array
index Number
amount Number

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

fromIndex Number
newIndex Number

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

index Number

removeQuadsAtIndex
(
  • index
  • amount
)

Removes a given number of quads at a given index.

index Number
amount Number

removeAllQuads ( )

Removes all Quads.
The TextureAtlas capacity remains untouched. No memory is freed.
The total number of quads to be drawn will be 0

resizeCapacity
(
  • newCapacity
)
Boolean

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

newCapacity Number

:

increaseTotalQuadsWith
(
  • amount
)

Used internally by CCParticleBatchNode
don't use this unless you know what you're doing.

amount Number

moveQuadsFromIndex
(
  • oldIndex
  • amount
  • newIndex
)

Moves an amount of quads from oldIndex at newIndex.

oldIndex Number
amount Number
newIndex Number

fillWithEmptyQuadsFromIndex
(
  • index
  • amount
)

Ensures that after a realloc quads are still empty
Used internally by CCParticleBatchNode.

index Number
amount Number

drawNumberOfQuads
(
  • n
  • start
)

Draws n quads from an index (offset).
n + start can't be greater than the capacity of the atlas

n Number
start Number

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index