Skip to content

Commit 06e33bc

Browse files
committed
Polygon & drawPolygon method
1 parent 1eca16a commit 06e33bc

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = function (grunt) {
1818
'src/pixi/core/Matrix.js',
1919
'src/pixi/core/Point.js',
2020
'src/pixi/core/Rectangle.js',
21+
'src/pixi/core/Polygon.js',
2122
'src/pixi/display/DisplayObject.js',
2223
'src/pixi/display/DisplayObjectContainer.js',
2324
'src/pixi/display/Sprite.js',
@@ -82,6 +83,7 @@ module.exports = function (grunt) {
8283
'src/geom/Circle.js',
8384
'src/geom/Point.js',
8485
'src/geom/Rectangle.js',
86+
'src/geom/Polygon.js',
8587
'src/net/Net.js',
8688
'src/tween/TweenManager.js',
8789
'src/tween/Tween.js',

src/gameobjects/Graphics.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ Phaser.Graphics.prototype.destroy = function() {
5050

5151
}
5252

53+
/*
54+
* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
55+
*/
56+
Phaser.Graphics.prototype.drawPolygon = function (poly) {
57+
58+
graphics.moveTo(poly.points[0].x, poly.points[0].y);
59+
for (var i = 1; i < poly.points.length; i += 1) {
60+
graphics.lineTo(poly.points[i].x, poly.points[i].y);
61+
}
62+
graphics.lineTo(poly.points[0].x, poly.points[0].y);
63+
}
64+
5365
Object.defineProperty(Phaser.Graphics.prototype, 'angle', {
5466

5567
get: function() {

src/geom/Polygon.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Phaser.Polygon = function (points) {
2+
3+
PIXI.Polygon.call(this, points);
4+
5+
/**
6+
* @property {Description} type - Description.
7+
*/
8+
this.type = Phaser.POLYGON;
9+
10+
};
11+
12+
Phaser.Polygon.prototype = Object.create(PIXI.Polygon.prototype);
13+
Phaser.Polygon.prototype.constructor = Phaser.Polygon;

0 commit comments

Comments
 (0)