2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* Creates a new `Graphics` object.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
|
|
|
* @class Phaser.Graphics
|
|
|
|
* @constructor
|
|
|
|
*
|
|
|
|
* @param {Phaser.Game} game Current game instance.
|
2013-10-25 14:22:45 +00:00
|
|
|
* @param {number} x - X position of the new graphics object.
|
|
|
|
* @param {number} y - Y position of the new graphics object.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 16:01:59 +00:00
|
|
|
Phaser.Graphics = function (game, x, y) {
|
|
|
|
|
2013-10-17 20:10:00 +00:00
|
|
|
this.game = game;
|
|
|
|
|
2013-09-22 14:21:51 +00:00
|
|
|
PIXI.Graphics.call(this);
|
2013-09-09 16:01:59 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {number} type - The Phaser Object Type.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-12 20:54:41 +00:00
|
|
|
this.type = Phaser.GRAPHICS;
|
|
|
|
|
2013-11-13 06:49:24 +00:00
|
|
|
this.position.x = x;
|
2013-11-25 03:13:04 +00:00
|
|
|
this.position.y = y;
|
2013-11-13 06:49:24 +00:00
|
|
|
|
2013-09-09 16:01:59 +00:00
|
|
|
};
|
|
|
|
|
2013-09-22 21:55:34 +00:00
|
|
|
Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype);
|
2013-09-09 16:01:59 +00:00
|
|
|
Phaser.Graphics.prototype.constructor = Phaser.Graphics;
|
2013-09-22 14:21:51 +00:00
|
|
|
|
2013-10-17 20:10:00 +00:00
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* Destroy this Graphics instance.
|
2013-10-17 20:10:00 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.destroy
|
|
|
|
*/
|
|
|
|
Phaser.Graphics.prototype.destroy = function() {
|
|
|
|
|
|
|
|
this.clear();
|
|
|
|
|
|
|
|
if (this.group)
|
|
|
|
{
|
|
|
|
this.group.remove(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.game = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-05 19:25:06 +00:00
|
|
|
/*
|
|
|
|
* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
|
|
|
|
*/
|
|
|
|
Phaser.Graphics.prototype.drawPolygon = function (poly) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.moveTo(poly.points[0].x, poly.points[0].y);
|
2013-11-13 06:49:24 +00:00
|
|
|
|
|
|
|
for (var i = 1; i < poly.points.length; i += 1)
|
|
|
|
{
|
2013-11-25 03:13:04 +00:00
|
|
|
this.lineTo(poly.points[i].x, poly.points[i].y);
|
2013-11-05 19:25:06 +00:00
|
|
|
}
|
2013-11-13 06:49:24 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.lineTo(poly.points[0].x, poly.points[0].y);
|
2013-11-13 06:49:24 +00:00
|
|
|
|
2013-11-05 19:25:06 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:01:59 +00:00
|
|
|
Object.defineProperty(Phaser.Graphics.prototype, 'angle', {
|
|
|
|
|
|
|
|
get: function() {
|
2013-10-17 20:10:00 +00:00
|
|
|
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.Graphics.prototype, 'x', {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
return this.position.x;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
|
|
|
this.position.x = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Phaser.Graphics.prototype, 'y', {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
return this.position.y;
|
2013-09-09 16:01:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
2013-10-17 20:10:00 +00:00
|
|
|
this.position.y = value;
|
2013-09-09 16:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|