Star
Introduction¶
Star shape, built-in game object of phaser.
- Author: Richard Davey
Usage¶
Create shape object¶
var star = scene.add.star(x, y, points, innerRadius, outerRadius, fillColor);
// var star = scene.add.star(x, y, points, innerRadius, outerRadius, fillColor, fillAlpha);
points: The number of points on the star. Default is 5.innerRadius: The inner radius of the star. Default is 32.outerRadius: The outer radius of the star. Default is 64.
Custom class¶
- Define class
class MyStar extends Phaser.GameObjects.Star { constructor(scene, x, y, points, innerRadius, outerRadius, fillColor) { super(scene, x, y, points, innerRadius, outerRadius, 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
preUpdatemethod, it will be added to the Update List.
- Create instance
var star = new MyStar(scene, x, y, points, innerRadius, outerRadius, fillColor);
Color¶
- Fill color
- Get
var color = star.fillColor; var alpha = star.fillAlpha; - Set
star.setFillStyle(color, alpha); - Clear
star.setFillStyle();
- Get
- Stroke color
- Get
var color = star.strokeColor; - Set
star.setStrokeStyle(lineWidth, color, alpha); - Clear
star.setStrokeStyle();
- Get
No tint methods
Uses star.setFillStyle(color, alpha) to change color.
Alpha¶
- Get
var alpha = star.alpha; - Set
star.setAlpha(alpha); // star.alpha = alpha;
Radius¶
- Inner radius
- Get
var innerRadius = star.innerRadius; - Set
or
star.setInnerRadius(innerRadius);star.innerRadius = innerRadius;
- Get
- Outer radius
- Get
var outerRadius = star.outerRadius; - Set
or
star.setOuterRadius(outerRadius);star.outerRadius = outerRadius;
- Get
- Points
- Get
var points = star.points; - Set
or
star.setPoints(points);star.points = points;
- Get
Display size¶
- Get
var width = star.displayWidth; var height = star.displayHeight; - Set
or
star.setDisplaySize(width, height);star.displayWidth = width; star.displayHeight = height;
Other properties¶
See game object
Create mask¶
var mask = star.createGeometryMask();
See mask
Shader effects¶
Support postFX effects
Note
No preFX effect support