How to use the drawTriangles function?

I’m learning Phaser and found the “drawTriangles” function. It’s in the Graphics object.

The “drawTriangles” function is needed for the project, please tell me how to use it correctly in Phaser?

Looked at the codes Phaser. Not in the examples?

Phaser 3 Graphics has no drawTriangles(), but it has fillTriangle(), fillTriangleShape(), strokeTriangle(), strokeTriangleShape().

There is such a function, for some reason my link was removed. Here is the link to the library:

https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.4/phaser.js

Just type in the Phaser script search to quickly find the line you need:

Phaser.Graphics.prototype.drawTriangles = function(vertices, indices, cull)

The Phaser 2 drawTriangles() method isn’t in Phaser 3.

I asked for an example with drawTriangles, not a link to the library. There is no example anywhere.

Are you using Phaser 2 or Phaser 3 in your project?

I use Phaser 2 because I need the drawTriangles function.

I would really recommend you use any of the Phaser 3 Graphics triangle methods.

I don’t know of any Phaser 2 drawTriangles() examples, but it would work like this:

// Phaser 2
const graphics = this.add.graphics(0, 0);

graphics.lineStyle(10, 0xffd900, 1);
graphics.beginFill(0xFF3300);
graphics.drawTriangles([0, 0, 50, 50, 100, 0, 150, 50, 200, 0, 250, 50]);
graphics.endFill();
1 Like