Curve

Introduction

Curve shape, built-in game object of phaser.

  • Author: Richard Davey

Usage

Create shape object

var curve = scene.add.curve(x, y, path, fillColor);
// var curve = scene.add.curve(x, y, path, fillColor, fillAlpha);

Custom class

  • Define class
    class MyCurve extends Phaser.GameObjects.Curve {
        constructor(scene, x, y, path, fillColor, fillAlpha) {
            super(scene, x, y, path, fillColor, fillAlpha);
            // ...
            scene.add.existing(this);
        }
        // ...
    
        // preUpdate(time, delta) {}
    }
    
    • scene.add.existing(gameObject) : Adds an existing Game Object to this Scene.
      • If the Game Object renders, it will be added to the Display List.
      • If it has a preUpdate method, it will be added to the Update List.
  • Create instance
    var curve = new MyCurve(scene, x, y, path, fillColor, fillAlpha);
    

Color

  • Fill color
    • Get
      var color = curve.fillColor;
      
    • Set
      curve.setFillStyle(color, alpha);
      
    • Clear
      curve.setFillStyle();
      
  • Stroke color
    • Get
      var color = curve.strokeColor;
      
    • Set
      curve.setStrokeStyle(lineWidth, color, alpha);
      
    • Clear
      curve.setStrokeStyle();
      

No tint methods

Uses curve.setFillStyle(color, alpha) to change color.

Smoothness

The number of points used when rendering it. Increase this value for smoother curves, at the cost of more polygons being rendered.

curve.setSmoothness(smoothness);
or
curve.smoothness = smoothness;

Other properties

See game object