Arc

Introduction

Arc shape, built-in game object of phaser.

  • Author: Richard Davey

Usage

Create shape

var arc = scene.add.arc(x, y, radius, startAngle, endAngle, anticlockwise, fillColor);
// var arc = scene.add.arc(x, y, radius, startAngle, endAngle, anticlockwise, fillColor, fillAlpha);

Custom class

  • Define class
    class MyArc extends Phaser.GameObjects.Arc {
        constructor(scene, x, y, radius, startAngle, endAngle, anticlockwise, fillColor) {
            super(scene, x, y, radius, startAngle, endAngle, anticlockwise, fillColor);
            // ...
            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 arc = new MyArc(scene, x, y, radius, startAngle, endAngle, anticlockwise, fillColor);
    

Color

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

No tint methods

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

Properties

  • Radius
    • Get
      var radius = arc.radius;
      
    • Set
      arc.setRadius(radius);
      
      or
      arc.radius = radius;
      
  • Start angle, in degrees.
    • Get
      var startAngle = arc.startAngle;
      
    • Set
      arc.setStartAngle(startAngle);
      // arc.setStartAngle(startAngle, anticlockwise);
      
      or
      arc.startAngle = startAngle;
      
  • End angle, in degrees.
    • Get
      var endAngle = arc.endAngle;
      
    • Set
      arc.seEndAngle(endAngle);
      
      or
      arc.endAngle = endAngle;
      
  • Anticlockwise (true, or false)
    • Get
      var anticlockwise = arc.anticlockwise;
      
    • Set
      arc.anticlockwise = anticlockwise;
      
  • Iterations: Increase this value for smoother arcs, at the cost of more polygons being rendered. Default is 0.01
    • Get
      var iterations = arc.iterations;
      
    • Set
      arc.iterations = iterations;
      

Other properties

See game object