Hexagon
Introduction¶
Hexagon shape and methods, extends from Polygon geometry object.
- Author: Rex
- Geometry object
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexhexagonplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexhexagonplugin.min.js', true);
- Add hexagon geometry object
var hexagon = scene.plugins.get('rexhexagonplugin').add(x, y, size, orientationType);
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Install plugin in configuration of game
import HexagonPlugin from 'phaser3-rex-plugins/plugins/hexagon-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexHexagon', plugin: HexagonPlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config);
- Add hexagon geometry object
var hexagon = scene.plugins.get('rexHexagon').add(x, y, size, orientationType);
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Import class
import Hexagon from 'phaser3-rex-plugins/plugins/hexagon.js';
- Add hexagon geometry object
var hexagon = new Hexagon(x, y, size, orientationType);
Create shape¶
var hexagon = scene.plugins.get('rexHexagon').add(x, y, size, orientationType);
var hexagon = scene.plugins.get('rexHexagon').add({
x: 0,
y: 0,
size: 20,
orientationType: 0 // 0|'flat'|'vertical'|1|'pointy'|'horizontal'
});
var hexagon = new Phaser.Geom.rexHexagon(x, y, size, orientationType);
x
: Center X.y
: Center Y.size
: Distance between center to each corner.orientationType
: See here0
,'flat'
, or'y'
1
,'pointy'
or ,'x'
Draw on graphics¶
See Polygon shape.
Set properties¶
- All properties
hexagon.setTo(x, y, size, orientationType);
- Position
or
hexagon.setPosition(x, y);
orhexagon.x = 0; hexagon.y = 0;
orhexagon.centerX = 0; // equal to hexagon.x hexagon.centerY = 0; // equal to hexagon.y
hexagon.left = 0; // hexagon.x hexagon.top = 0; // hexagon.y hexagon.right = 0; // hexagon.x hexagon.bottom = 0; // hexagon.y
- Size
or
hexagon.setSize(size);
hexagon.size = size;
- Orientation type
or
hexagon.setType(orientationType);
hexagon.orientationType = orientationType;
orientationType
: See here0
,'flat'
, or'y'
1
,'pointy'
or ,'x'
Get properties¶
See Polygon shape.
- Position
- Center
or
var centerX = hexagon.centerX; var centerY = hexagon.centerY;
var centerX = hexagon.x; var centerY = hexagon.y;
- Bound
var top = hexagon.top; var left = hexagon.left; var right = hexagon.right; var bottom = hexagon.bottom;
- Center
- Width
var width = hexagon.width;
- Height
var width = hexagon.height;
- Lines around hexagon
or
var edge01 = hexagon.getLineA(); var edge12 = hexagon.getLineB(); var edge23 = hexagon.getLineC(); var edge34 = hexagon.getLineD(); var edge45 = hexagon.getLineE(); var edge50 = hexagon.getLineF(); // var out = hexagon.getLineF(out);
var edge = hexagon.getEdge(edgeIdx); // var out = hexagon.getEdge(edgeIdx, out);
Point(s) & shape¶
See Polygon shape.