Cocos Creator API

1.4.x

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

TextureAtlas

Module: 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.

Properties

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

Methods

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

name type description
fileName String | Texture2D
capacity Number

examples:

--------------------------
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.

returns:

type: Number

getCapacity ( ) Number

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

returns:

type: Number

getTexture ( ) Image

Texture of the texture atlas.

returns:

type: Image

setTexture
(
  • texture
)

Set texture for texture atlas.

name type description
texture Image

setDirty
(
  • dirty
)

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

name type description
dirty Boolean

isDirty ( ) Boolean

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

returns:

type: Boolean

getQuads ( ) Array

Quads that are going to be rendered.

returns:

type: Array

setQuads
(
  • quads
)

name type description
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.

name type description