[Phaser.Geom.Polygon] Smooth - not callable

Hey guys :slightly_smiling_face:
I am trying to smoothen a polygon, but it keeps saying that “smooth” is not a function. Here it is in the docs:

Phaser code:

My code goes here

const polygon = new Phaser.Geom.Polygon(coords);
polygon.smooth(1);

Docs are saying:
Smooths the polygon over the number of iterations specified.
polygon.smooth(iterations);

console: TypeError: polygon.smooth is not a function

  • I doublechecked that the polygon is created correctly
  • I also called smooth after applying it to a graphics

what am I missing hear, you got an idea? Reading the docs it should work I think.
Using Phaser 3 version: 3.18.1

cheers

The function you’re looking at exists on the Polygon Game Object (Phaser.GameObjects.Polygon), but you’re working with the geometric shape (Phaser.Geom.Polygon). The Game Object can be rendered to a scene (just like any other Game Object), while the geometric shape is a logical representation of a polygon.

If you want to use the Game Object, you’ll have to instantiate the correct class (new Phaser.GameObjects.Polygon(scene, coords)) or use the Game Object Factory (scene.add.polygon).

If the geometric shape is actually what you want to use, the smoothing method for it is static - Phaser.Geom.Polygon.Smooth.

2 Likes