|
4 | 4 | * @license {@link https://opensource.org/licenses/MIT|MIT License} |
5 | 5 | */ |
6 | 6 |
|
| 7 | +var CONST = require('../const.js'); |
7 | 8 | var Class = require('../utils/Class'); |
8 | 9 | var Components = require('../gameobjects/components'); |
9 | 10 | var Rectangle = require('../geom/rectangle'); |
@@ -706,14 +707,34 @@ var Tile = new Class({ |
706 | 707 | */ |
707 | 708 | updatePixelXY: function () |
708 | 709 | { |
709 | | - // Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the |
710 | | - // bottom left, while the Phaser renderer assumes the origin is the top left. The y |
711 | | - // coordinate needs to be adjusted by the difference. |
712 | | - this.pixelX = this.x * this.baseWidth; |
713 | | - this.pixelY = this.y * this.baseHeight; |
714 | | - |
715 | | - // this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight); |
716 | | - |
| 710 | + if (this.layer.orientation === CONST.ISOMETRIC) |
| 711 | + { |
| 712 | + // reminder : for the tilemap to be centered we have to move the image to the right with the camera ! |
| 713 | + // this is crucial for wordtotile, tiletoworld to work. |
| 714 | + this.pixelX = (this.x - this.y) * this.baseWidth * 0.5; |
| 715 | + this.pixelY = (this.x + this.y) * this.baseHeight * 0.5; |
| 716 | + } |
| 717 | + else if (this.layer.orientation === CONST.STAGGERED) |
| 718 | + { |
| 719 | + this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2); |
| 720 | + this.pixelY = this.y * (this.baseHeight / 2); |
| 721 | + } |
| 722 | + else if (this.layer.orientation === CONST.HEXAGONAL) |
| 723 | + { |
| 724 | + var sidel = this.layer.hexSideLength; |
| 725 | + var rowHeight = ((this.baseHeight - sidel) / 2 + sidel); |
| 726 | + this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2); |
| 727 | + this.pixelY = this.y * rowHeight; |
| 728 | + } |
| 729 | + else if (this.layer.orientation === CONST.ORTHOGONAL) |
| 730 | + { |
| 731 | + // In orthogonal mode, Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the |
| 732 | + // bottom left, while the Phaser renderer assumes the origin is the top left. The y |
| 733 | + // coordinate needs to be adjusted by the difference. |
| 734 | + this.pixelX = this.x * this.baseWidth; |
| 735 | + this.pixelY = this.y * this.baseHeight; |
| 736 | + |
| 737 | + } |
717 | 738 | return this; |
718 | 739 | }, |
719 | 740 |
|
|
0 commit comments