Phaser API Documentation

  Version: 
addVertices(vertices, uvs, [indicies], [containsZ], [normals], [colors], [alphas])

Description:

Adds new vertices to this Mesh by parsing the given data.

This method will take vertex data in one of two formats, based on the containsZ parameter.

If your vertex data are x, y pairs, then containsZ should be false (this is the default, and will result in z=0 for each vertex).

If your vertex data is groups of x, y and z values, then the containsZ parameter must be true.

The uvs parameter is a numeric array consisting of u and v pairs.

The normals parameter is a numeric array consisting of x, y vertex normal values and, if containsZ is true, z values as well.

The indicies parameter is an optional array that, if given, is an indexed list of vertices to be added.

The colors parameter is an optional array, or single value, that if given sets the color of each vertex created.

The alphas parameter is an optional array, or single value, that if given sets the alpha of each vertex created.

When providing indexed data it is assumed that all of the arrays are indexed, not just the vertices.

The following example will create a 256 x 256 sized quad using an index array:

let mesh = new Mesh(this);  // Assuming `this` is a scene!
const vertices = [
  -128, 128,
  128, 128,
  -128, -128,
  128, -128
];

const uvs = [
  0, 1,
  1, 1,
  0, 0,
  1, 0
];

const indices = [ 0, 2, 1, 2, 3, 1 ];

mesh.addVertices(vertices, uvs, indicies);
// Note: Otherwise the added points will be "behind" the camera! This value will project vertex `x` & `y` values 1:1 to pixel values.
mesh.hideCCW = false;
mesh.setOrtho(mesh.width, mesh.height);

If the data is not indexed, it's assumed that the arrays all contain sequential data.

Parameters:

name type arguments Default description
vertices Array.<number>

The vertices array. Either xy pairs, or xyz if the containsZ parameter is true.

uvs Array.<number>

The UVs pairs array.

indicies Array.<number> <optional>

Optional vertex indicies array. If you don't have one, pass null or an empty array.

containsZ boolean <optional> false

Does the vertices data include a z component? If not, it will be assumed z=0, see methods panZ or setOrtho.

normals Array.<number> <optional>

Optional vertex normals array. If you don't have one, pass null or an empty array.

colors number | Array.<number> <optional> 0xffffff

An array of colors, one per vertex, or a single color value applied to all vertices.

alphas number | Array.<number> <optional> 1

An array of alpha values, one per vertex, or a single alpha value applied to all vertices.

Returns:
Description:

This Mesh Game Object.

Since: 3.50.0