|
| 1 | +Phaser.Graphics = function (game, x, y) { |
| 2 | + |
| 3 | + // If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all |
| 4 | + this.exists = true; |
| 5 | + |
| 6 | + // This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering |
| 7 | + this.alive = true; |
| 8 | + |
| 9 | + this.group = null; |
| 10 | + |
| 11 | + this.name = ''; |
| 12 | + |
| 13 | + this.game = game; |
| 14 | + |
| 15 | + PIXI.DisplayObjectContainer.call(this); |
| 16 | + |
| 17 | + this.position.x = x; |
| 18 | + this.position.y = y; |
| 19 | + |
| 20 | + // Replaces the PIXI.Point with a slightly more flexible one |
| 21 | + this.scale = new Phaser.Point(1, 1); |
| 22 | + |
| 23 | + // Influence of camera movement upon the position |
| 24 | + this.scrollFactor = new Phaser.Point(1, 1); |
| 25 | + |
| 26 | + // A mini cache for storing all of the calculated values |
| 27 | + this._cache = { |
| 28 | + |
| 29 | + dirty: false, |
| 30 | + |
| 31 | + // Transform cache |
| 32 | + a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1, |
| 33 | + |
| 34 | + // The previous calculated position inc. camera x/y and scrollFactor |
| 35 | + x: -1, y: -1, |
| 36 | + |
| 37 | + // The actual scale values based on the worldTransform |
| 38 | + scaleX: 1, scaleY: 1 |
| 39 | + |
| 40 | + }; |
| 41 | + |
| 42 | + this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); |
| 43 | + this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); |
| 44 | + |
| 45 | + this.renderable = true; |
| 46 | + |
| 47 | + /** |
| 48 | + * The alpha of the fill of this graphics object |
| 49 | + * |
| 50 | + * @property fillAlpha |
| 51 | + * @type Number |
| 52 | + */ |
| 53 | + this.fillAlpha = 1; |
| 54 | + |
| 55 | + /** |
| 56 | + * The width of any lines drawn |
| 57 | + * |
| 58 | + * @property lineWidth |
| 59 | + * @type Number |
| 60 | + */ |
| 61 | + this.lineWidth = 0; |
| 62 | + |
| 63 | + /** |
| 64 | + * The color of any lines drawn |
| 65 | + * |
| 66 | + * @property lineColor |
| 67 | + * @type String |
| 68 | + */ |
| 69 | + this.lineColor = "black"; |
| 70 | + |
| 71 | + /** |
| 72 | + * Graphics data |
| 73 | + * |
| 74 | + * @property graphicsData |
| 75 | + * @type Array |
| 76 | + * @private |
| 77 | + */ |
| 78 | + this.graphicsData = []; |
| 79 | + |
| 80 | + /** |
| 81 | + * Current path |
| 82 | + * |
| 83 | + * @property currentPath |
| 84 | + * @type Object |
| 85 | + * @private |
| 86 | + */ |
| 87 | + this.currentPath = {points:[]}; |
| 88 | + |
| 89 | +}; |
| 90 | + |
| 91 | +Phaser.Graphics.prototype = Phaser.Utils.extend(true, PIXI.Graphics.prototype, PIXI.DisplayObjectContainer.prototype, Phaser.Sprite.prototype); |
| 92 | +Phaser.Graphics.prototype.constructor = Phaser.Graphics; |
| 93 | + |
| 94 | +// Add our own custom methods |
| 95 | + |
| 96 | +/** |
| 97 | + * Automatically called by World.update |
| 98 | + */ |
| 99 | +Phaser.Graphics.prototype.update = function() { |
| 100 | + |
| 101 | + if (!this.exists) |
| 102 | + { |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + this._cache.dirty = false; |
| 107 | + |
| 108 | + this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); |
| 109 | + this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); |
| 110 | + |
| 111 | + if (this.position.x != this._cache.x || this.position.y != this._cache.y) |
| 112 | + { |
| 113 | + this.position.x = this._cache.x; |
| 114 | + this.position.y = this._cache.y; |
| 115 | + this._cache.dirty = true; |
| 116 | + } |
| 117 | + |
| 118 | +} |
| 119 | + |
| 120 | +Object.defineProperty(Phaser.Graphics.prototype, 'angle', { |
| 121 | + |
| 122 | + get: function() { |
| 123 | + return Phaser.Math.radToDeg(this.rotation); |
| 124 | + }, |
| 125 | + |
| 126 | + set: function(value) { |
| 127 | + this.rotation = Phaser.Math.degToRad(value); |
| 128 | + } |
| 129 | + |
| 130 | +}); |
| 131 | + |
| 132 | +Object.defineProperty(Phaser.Graphics.prototype, 'x', { |
| 133 | + |
| 134 | + get: function() { |
| 135 | + return this.position.x; |
| 136 | + }, |
| 137 | + |
| 138 | + set: function(value) { |
| 139 | + this.position.x = value; |
| 140 | + } |
| 141 | + |
| 142 | +}); |
| 143 | + |
| 144 | +Object.defineProperty(Phaser.Graphics.prototype, 'y', { |
| 145 | + |
| 146 | + get: function() { |
| 147 | + return this.position.y; |
| 148 | + }, |
| 149 | + |
| 150 | + set: function(value) { |
| 151 | + this.position.y = value; |
| 152 | + } |
| 153 | + |
| 154 | +}); |
0 commit comments