Phaser.Graphics = function (game, x, y){ if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } this.type = Phaser.GRAPHICS; this.physicsType = Phaser.SPRITE; PIXI.Graphics.call(this); Phaser.Component.Core.init.call(this, game, x, y, '', null ); } ; Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype); Phaser.Graphics.prototype.constructor = Phaser.Graphics; Phaser.Component.Core.install.call(Phaser.Graphics.prototype, ['Angle', 'AutoCull', 'Bounds', 'Destroy', 'FixedToCamera', 'InputEnabled', 'InWorld', 'LifeSpan', 'PhysicsBody', 'Reset'] ); Phaser.Graphics.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate; Phaser.Graphics.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate; Phaser.Graphics.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate; Phaser.Graphics.prototype.preUpdateCore = Phaser.Component.Core.preUpdate; Phaser.Graphics.prototype.preUpdate = function (){ if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld()) { return false ; } return this.preUpdateCore(); } ; Phaser.Graphics.prototype.destroy = function (destroyChildren){ _AN_Call_clear('clear', this); Phaser.Component.Destroy.prototype.destroy.call(this, destroyChildren); } ; Phaser.Graphics.prototype.drawTriangle = function (points, cull){ if (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 (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 = [] ; } } } } } ;