Phaser.Graphics = function (game, x, y){ x = x || 0; y = y || 0; this.game = game; this.exists = true ; this.name = ''; this.type = Phaser.GRAPHICS; this.z = 0; this.world = new Phaser.Point(x, y); this.cameraOffset = new Phaser.Point(); PIXI.Graphics.call(this); this.position.set(x, y); this._cache = [0, 0, 0, 0, 1, 0, 1, 0, 0] ; } ; Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype); Phaser.Graphics.prototype.constructor = Phaser.Graphics; Phaser.Graphics.prototype.preUpdate = function (){ this._cache[0] = this.world.x; this._cache[1] = this.world.y; this._cache[2] = this.rotation; if (!this.exists || !this.parent.exists) { this.renderOrderID = -1; return false ; } if (this.autoCull) { this.renderable = this.game.world.camera.screenView.intersects(this.getBounds()); } this.world.setTo(this.game.camera.x + this.worldTransform.tx, this.game.camera.y + this.worldTransform.ty); if (this.visible) { this._cache[3] = this.game.stage.currentRenderOrderID++ ; } return true ; } ; Phaser.Graphics.prototype.update = function (){ } ; Phaser.Graphics.prototype.postUpdate = function (){ if (this._cache[7] === 1) { this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x; this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y; } } ; Phaser.Graphics.prototype.destroy = function (destroyChildren){ if (this.game === null || this.destroyPhase) { return ; } if (typeof destroyChildren === 'undefined') { destroyChildren = true ; } this._cache[8] = 1; _AN_Call_clear('clear', this); if (this.parent) { if (this.parent instanceof Phaser.Group) { this.parent.remove(this); } else { this.parent.removeChild(this); } } var i = _AN_Read_length('length', this.children); if (destroyChildren) { while (i-- ){ this.children[i].destroy(destroyChildren); } } else { while (i-- ){ this.removeChild(this.children[i]); } } this.exists = false ; this.visible = false ; this.game = null ; this._cache[8] = 0; } ; Phaser.Graphics.prototype.drawCircle = function (x, y, diameter){ this.drawShape(new Phaser.Circle(x, y, diameter)); return this; } ; Phaser.Graphics.prototype.drawTriangle = function (points, cull){ if (typeof cull === 'undefined') { cull = false ; } var triangle = new Phaser.Polygon(points); if (cull) { var cameraToFace = new Phaser.Point(this.game.camera.x - points[0].x, this.game.camera.y - points[0].y); var ab = new Phaser.Point(points[1].x - points[0].x, points[1].y - points[0].y); var cb = new Phaser.Point(points[1].x - points[2].x, points[1].y - points[2].y); var faceNormal = cb.cross(ab); if (cameraToFace.dot(faceNormal) > 0) { this.drawPolygon(triangle); } } else { this.drawPolygon(triangle); } } ; Phaser.Graphics.prototype.drawTriangles = function (vertices, indices, cull){ if (typeof cull === 'undefined') { cull = false ; } var point1 = new Phaser.Point(); var point2 = new Phaser.Point(); var point3 = new Phaser.Point(); var points = [] ; var i; if (!indices) { if (vertices[0] instanceof Phaser.Point) { for (i = 0; i < _AN_Read_length('length', vertices) / 3; i++ ){ this.drawTriangle([vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]] , cull); } } else { for (i = 0; i < _AN_Read_length('length', vertices) / 6; i++ ){ point1.x = vertices[i * 6 + 0]; point1.y = vertices[i * 6 + 1]; point2.x = vertices[i * 6 + 2]; point2.y = vertices[i * 6 + 3]; point3.x = vertices[i * 6 + 4]; point3.y = vertices[i * 6 + 5]; this.drawTriangle([point1, point2, point3] , cull); } } } else { if (vertices[0] instanceof Phaser.Point) { for (i = 0; i < _AN_Read_length('length', indices) / 3; i++ ){ points.push(vertices[indices[i * 3]]); points.push(vertices[indices[i * 3 + 1]]); points.push(vertices[indices[i * 3 + 2]]); if (_AN_Read_length('length', points) === 3) { this.drawTriangle(points, cull); points = [] ; } } } else { for (i = 0; i < _AN_Read_length('length', indices); i++ ){ point1.x = vertices[indices[i] * 2]; point1.y = vertices[indices[i] * 2 + 1]; points.push(point1.copyTo({ } )); if (_AN_Read_length('length', points) === 3) { this.drawTriangle(points, cull); points = [] ; } } } } } ; Object.defineProperty(Phaser.Graphics.prototype, 'angle', { get: function (){ return Phaser.Math.radToDeg(this.rotation); } , set: function (value){ this.rotation = Phaser.Math.degToRad(value); } } ); Object.defineProperty(Phaser.Graphics.prototype, "fixedToCamera", { get: function (){ return !!this._cache[7]; } , set: function (value){ if (value) { this._cache[7] = 1; this.cameraOffset.set(this.x, this.y); } else { this._cache[7] = 0; } } } ); Object.defineProperty(Phaser.Graphics.prototype, "destroyPhase", { get: function (){ return !!this._cache[8]; } } );