|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | /** |
8 | | -* A TilemapLayerGL is a PIXI.Tilemap that renders a specific TileLayer of a Tilemap. |
| 8 | +* A TilemapLayerGL is a PIXI.Tilemap that renders a specific TileLayer of a Tilemap using the PIXI WebGl renderer. |
| 9 | +* NOTE: this is a close duplicate of Phaser.TilemapLayer modified to support WebGl rendering, it may be possible to merge the two classes |
| 10 | +* although that will probably incur performance penalties due to some fundamental differences in the set-up before rendering. |
| 11 | +* Ideally it would be great to make this extend Phaser.TilemapLayer and get access to its methods in that way, however as this needs to |
| 12 | +* extend PIXI.Tilemap, and Phaser.TilemapLayer extends Phaser.DisplayObject. I can't see a way to achieve that merge. |
9 | 13 | * |
| 14 | +* |
10 | 15 | * Since a PIXI.Tilemap is a PIXI.DisplayObjectContainer it can be moved around the display, added to other groups or display objects, etc. |
11 | 16 | * |
12 | 17 | * By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior. |
@@ -234,17 +239,23 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height) { |
234 | 239 |
|
235 | 240 | Phaser.Component.Core.init.call(this, game, 0, 0, null, null); |
236 | 241 |
|
237 | | - // must be called after the Core.init |
| 242 | + // must be set *after* the Core.init |
238 | 243 | this.fixedToCamera = true; |
239 | 244 | }; |
240 | 245 |
|
| 246 | + |
| 247 | +// constructor: extends PIXI.Tilemap |
241 | 248 | Phaser.TilemapLayerGL.prototype = Object.create(PIXI.Tilemap.prototype); |
242 | 249 | Phaser.TilemapLayerGL.prototype.constructor = Phaser.TilemapLayerGL; |
243 | 250 |
|
| 251 | + |
| 252 | +// only one Phaser component used |
244 | 253 | Phaser.Component.Core.install.call(Phaser.TilemapLayerGL.prototype, [ |
245 | 254 | 'FixedToCamera' |
246 | 255 | ]); |
247 | 256 |
|
| 257 | + |
| 258 | +// redirect method prototypes (TODO: not needed? I'm not sure...) |
248 | 259 | Phaser.TilemapLayerGL.prototype.preUpdateCore = Phaser.Component.Core.preUpdate; |
249 | 260 | Phaser.TileSprite.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate; |
250 | 261 | Phaser.TileSprite.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate; |
@@ -706,45 +717,17 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left, |
706 | 717 |
|
707 | 718 | var index = tile.index; |
708 | 719 |
|
709 | | - // if (tile.alpha !== lastAlpha && !this.debug) |
710 | | - // { |
711 | | - // //context.globalAlpha = tile.alpha; |
712 | | - // lastAlpha = tile.alpha; |
713 | | - // } |
714 | | - |
715 | 720 | if (tile.rotation || tile.flipped) |
716 | 721 | { |
717 | | - //context.save(); |
718 | | - //context.translate(tx + tile.centerX, ty + tile.centerY); |
719 | | - //context.rotate(tile.rotation); |
720 | | - |
721 | | - // if (tile.flipped) |
722 | | - // { |
723 | | - // context.scale(-1, 1); |
724 | | - // } |
725 | | - |
726 | 722 | this._mc.tileset.drawGl(this.glBatch, -tile.centerX + offx, -tile.centerY + offy, index, tile.alpha); |
727 | | - //context.restore(); |
728 | 723 | } |
729 | 724 | else |
730 | 725 | { |
731 | 726 | this._mc.tileset.drawGl(this.glBatch, tx + offx, ty + offy, index, tile.alpha); |
732 | 727 | } |
733 | | - // if (!this._mc.tileset && this.debugSettings.missingImageFill) |
734 | | - // { |
735 | | - // context.fillStyle = this.debugSettings.missingImageFill; |
736 | | - // context.fillRect(tx, ty, tw, th); |
737 | | - // } |
738 | | - |
739 | | - // if (tile.debug && this.debugSettings.debuggedTileOverfill) |
740 | | - // { |
741 | | - // context.fillStyle = this.debugSettings.debuggedTileOverfill; |
742 | | - // context.fillRect(tx, ty, tw, th); |
743 | | - // } |
744 | | - |
745 | 728 | } |
746 | 729 |
|
747 | | - // at end of each row, add a degenerate marker into the batch list |
| 730 | + // at end of each row, add a degenerate marker into the batch drawing list |
748 | 731 | this._mc.tileset.addDegenerate( this.glBatch ); |
749 | 732 | } |
750 | 733 |
|
|
0 commit comments