Class: TextureAtlas

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.

Constructor

new TextureAtlas()

Properties:
Name Type Description
texture pc.Texture The texture atlas.
frames Object Contains frames which define portions of the texture atlas.
Source:
Example
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)
  },
  ...
};

Methods

destroy()

Free up the underlying WebGL resource owned by the texture.
Source:

removeFrame(key)

Parameters:
Name Type Description
key String The key of the frame.
Source:
Example
atlas.removeFrame('1');

setFrame(key, data)

Parameters:
Name Type Description
key String The key of the frame.
data Object The properties of the frame.
Properties
Name Type Attributes Description
rect pc.Vec4 <optional>
The u, v, width, height properties of the frame in pixels.
pivot pc.Vec2 <optional>
The pivot of the frame - values are between 0-1.
border pc.Vec4 <optional>
The border of the frame for 9-slicing. Values are left, bottom, right, top border in pixels.
Source:
Example
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)
});