phaser/src/gameobjects/Graphics.js

71 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-10-01 12:54:29 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2014-02-05 05:54:25 +00:00
* @copyright 2014 Photon Storm Ltd.
2013-10-01 12:54:29 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Creates a new `Graphics` object.
2013-10-01 12:54:29 +00:00
*
* @class Phaser.Graphics
* @constructor
*
* @param {Phaser.Game} game Current game instance.
* @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
*/
Phaser.Graphics = function (game, x, y) {
this.game = game;
2013-09-22 14:21:51 +00:00
PIXI.Graphics.call(this);
2013-10-01 12:54:29 +00:00
/**
* @property {number} type - The Phaser Object Type.
2013-10-01 12:54:29 +00:00
*/
this.type = Phaser.GRAPHICS;
this.position.x = x;
this.position.y = y;
};
2013-09-22 21:55:34 +00:00
Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype);
Phaser.Graphics.prototype.constructor = Phaser.Graphics;
2013-09-22 14:21:51 +00:00
/**
* Destroy this Graphics instance.
*
* @method Phaser.Sprite.prototype.destroy
*/
Phaser.Graphics.prototype.destroy = function() {
this.clear();
if (this.parent)
{
this.parent.remove(this);
}
this.game = null;
}
2013-11-05 19:25:06 +00:00
/*
* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
*
* @method Phaser.Sprite.prototype.drawPolygon
2013-11-05 19:25:06 +00:00
*/
Phaser.Graphics.prototype.drawPolygon = function (poly) {
this.moveTo(poly.points[0].x, poly.points[0].y);
for (var i = 1; i < poly.points.length; i += 1)
{
this.lineTo(poly.points[i].x, poly.points[i].y);
2013-11-05 19:25:06 +00:00
}
this.lineTo(poly.points[0].x, poly.points[0].y);
2013-11-05 19:25:06 +00:00
}