API Reference

Class List

pc.TextureAtlas

A pc.TextureAtlas contains a number of frames from a texture. Each frame defines a region in a texture. The pc.TextureAtlas is referenced by pc.Sprites.

var atlas = new pc.TextureAtlas();
atlas.frames = {
  '0': {
      // rect has u, v, width and height in pixels
      rect: new pc.Vec4(0, 0, 256, 256),
      // pivot has x, y values between 0-1 which define the point
      // within the frame around which rotation and scale is calculated
      pivot: new pc.Vec2(0.5, 0.5),
.      // border has left, bottom, right and top in pixels defining regions for 9-slicing
.      border: new pc.Vec4(5, 5, 5, 5)
  },
  '1': {
      rect: new pc.Vec4(256, 0, 256, 256),
      pivot: new pc.Vec2(0.5, 0.5),
      border: new pc.Vec4(5, 5, 5, 5)
  },
  ...
};

Summary

Properties

framesContains frames which define portions of the texture atlas.
textureThe texture atlas.

Methods

destroyFree up the underlying WebGL resource owned by the texture.
removeFrame
setFrame

Details

Constructor

TextureAtlas()

var atlas = new pc.TextureAtlas();
atlas.frames = {
  '0': {
      // rect has u, v, width and height in pixels
      rect: new pc.Vec4(0, 0, 256, 256),
      // pivot has x, y values between 0-1 which define the point
      // within the frame around which rotation and scale is calculated
      pivot: new pc.Vec2(0.5, 0.5),
.      // border has left, bottom, right and top in pixels defining regions for 9-slicing
.      border: new pc.Vec4(5, 5, 5, 5)
  },
  '1': {
      rect: new pc.Vec4(256, 0, 256, 256),
      pivot: new pc.Vec2(0.5, 0.5),
      border: new pc.Vec4(5, 5, 5, 5)
  },
  ...
};

Properties

Objectframes

Contains frames which define portions of the texture atlas.

pc.Texturetexture

The texture atlas.

Methods

destroy()

Free up the underlying WebGL resource owned by the texture.

removeFrame(key)

atlas.removeFrame('1');

Parameters

keyStringThe key of the frame.

setFrame(key, data)

atlas.setFrame('1', {
   rect: new pc.Vec4(0,0,128,128),
   pivot: new pc.Vec2(0.5, 0.5),
   border: new pc.Vec4(5, 5, 5, 5)
});

Parameters

keyStringThe key of the frame.
dataObjectThe properties of the frame.
data.rectpc.Vec4The u, v, width, height properties of the frame in pixels.
data.pivotpc.Vec2The pivot of the frame - values are between 0-1.
data.borderpc.Vec4The border of the frame for 9-slicing. Values are left, bottom, right, top border in pixels.