Cocos Creator API

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

属性(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

方法

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.

返回:

类型: Boolean

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

返回:

类型: Boolean

示例:

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

返回:

类型: Boolean

示例:

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

名称 类型 描述
quad V3F_C4B_T2F_Quad
index Number

insertQuad
(
  • quad
  • index
)

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

名称 类型 描述
quad V3F_C4B_T2F_Quad
index Number

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

返回:

类型: Boolean

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