From 06e33bc8e46e199a0f71f056f6f857d165178e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20Jim=C3=A9nez?= Date: Tue, 5 Nov 2013 20:25:06 +0100 Subject: [PATCH 1/2] Polygon & drawPolygon method --- Gruntfile.js | 2 ++ src/gameobjects/Graphics.js | 12 ++++++++++++ src/geom/Polygon.js | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/geom/Polygon.js diff --git a/Gruntfile.js b/Gruntfile.js index 0e12c14b..0bdda1f2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -18,6 +18,7 @@ module.exports = function (grunt) { 'src/pixi/core/Matrix.js', 'src/pixi/core/Point.js', 'src/pixi/core/Rectangle.js', + 'src/pixi/core/Polygon.js', 'src/pixi/display/DisplayObject.js', 'src/pixi/display/DisplayObjectContainer.js', 'src/pixi/display/Sprite.js', @@ -82,6 +83,7 @@ module.exports = function (grunt) { 'src/geom/Circle.js', 'src/geom/Point.js', 'src/geom/Rectangle.js', + 'src/geom/Polygon.js', 'src/net/Net.js', 'src/tween/TweenManager.js', 'src/tween/Tween.js', diff --git a/src/gameobjects/Graphics.js b/src/gameobjects/Graphics.js index e2303e9f..a164dd71 100644 --- a/src/gameobjects/Graphics.js +++ b/src/gameobjects/Graphics.js @@ -50,6 +50,18 @@ Phaser.Graphics.prototype.destroy = function() { } +/* +* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled +*/ +Phaser.Graphics.prototype.drawPolygon = function (poly) { + + graphics.moveTo(poly.points[0].x, poly.points[0].y); + for (var i = 1; i < poly.points.length; i += 1) { + graphics.lineTo(poly.points[i].x, poly.points[i].y); + } + graphics.lineTo(poly.points[0].x, poly.points[0].y); +} + Object.defineProperty(Phaser.Graphics.prototype, 'angle', { get: function() { diff --git a/src/geom/Polygon.js b/src/geom/Polygon.js new file mode 100644 index 00000000..20c380f3 --- /dev/null +++ b/src/geom/Polygon.js @@ -0,0 +1,13 @@ +Phaser.Polygon = function (points) { + + PIXI.Polygon.call(this, points); + + /** + * @property {Description} type - Description. + */ + this.type = Phaser.POLYGON; + +}; + +Phaser.Polygon.prototype = Object.create(PIXI.Polygon.prototype); +Phaser.Polygon.prototype.constructor = Phaser.Polygon; \ No newline at end of file From 35dd98c72f3d46e86000f24f3b040cc86b1b705f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20Jim=C3=A9nez?= Date: Tue, 5 Nov 2013 20:31:33 +0100 Subject: [PATCH 2/2] Added some docstring to the Polygon class --- src/geom/Polygon.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/geom/Polygon.js b/src/geom/Polygon.js index 20c380f3..a3c689b1 100644 --- a/src/geom/Polygon.js +++ b/src/geom/Polygon.js @@ -1,3 +1,14 @@ +/** +* Creates a new Polygon. You have to provide a list of points +* @class Phaser.Polygon +* @classdesc The polygon represents a list of orderded points in space +* @constructor +* @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon, +* a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be +* all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the +* arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are +* Numbers. +**/ Phaser.Polygon = function (points) { PIXI.Polygon.call(this, points);