@@ -25,8 +25,14 @@ var Tile = new Class({
2525 * @param {integer } y - The y coordinate of this tile in tile coordinates.
2626 * @param {integer } width - Width of the tile in pixels.
2727 * @param {integer } height - Height of the tile in pixels.
28+ * @param {integer } baseWidth - The base width a tile in the map (in pixels). Tiled maps support
29+ * multiple tileset sizes within one map, but they are still placed at intervals of the base
30+ * tile width.
31+ * @param {integer } baseHeight - The base height of the tile in pixels (in pixels). Tiled maps
32+ * support multiple tileset sizes within one map, but they are still placed at intervals of the
33+ * base tile height.
2834 */
29- function Tile ( layer , index , x , y , width , height )
35+ function Tile ( layer , index , x , y , width , height , baseWidth , baseHeight )
3036 {
3137 /**
3238 * The LayerData in the Tilemap data that this tile belongs to.
@@ -53,20 +59,6 @@ var Tile = new Class({
5359 */
5460 this . y = y ;
5561
56- /**
57- * The world x coordinate of this tile in pixels. This does not factor in camera scroll,
58- * layer scale or layer position.
59- * @property {number } x
60- */
61- this . worldX = x * width ;
62-
63- /**
64- * The world y coordinate of this tile in pixels. This does not factor in camera scroll,
65- * layer scale or layer position.
66- * @property {number } y
67- */
68- this . worldY = y * height ;
69-
7062 /**
7163 * The width of the tile in pixels.
7264 * @property {integer } width
@@ -79,6 +71,37 @@ var Tile = new Class({
7971 */
8072 this . height = height ;
8173
74+ /**
75+ * The map's base width of a tile in pixels. Tiled maps support multiple tileset sizes
76+ * within one map, but they are still placed at intervals of the base tile size.
77+ * @property {integer } baseWidth
78+ */
79+ this . baseWidth = ( baseWidth !== undefined ) ? baseWidth : width ;
80+
81+ /**
82+ * The map's base height of a tile in pixels. Tiled maps support multiple tileset sizes
83+ * within one map, but they are still placed at intervals of the base tile size.
84+ * @property {integer } baseHeight
85+ */
86+ this . baseHeight = ( baseHeight !== undefined ) ? baseHeight : height ;
87+
88+
89+ /**
90+ * The world x coordinate of the top left of this tile in pixels. This does not factor in
91+ * camera scroll, layer scale or layer position.
92+ * @property {number } x
93+ */
94+ this . worldX = 0 ;
95+
96+ /**
97+ * The world y coordinate of the top left of this tile in pixels. This does not factor in
98+ * camera scroll, layer scale or layer position.
99+ * @property {number } y
100+ */
101+ this . worldY = 0 ;
102+
103+ this . updateWorldXY ( ) ;
104+
82105 /**
83106 * Tile specific properties. These usually come from Tiled.
84107 * @property {object } properties
@@ -321,14 +344,34 @@ var Tile = new Class({
321344 *
322345 * @param {integer } tileWidth - The width of the tile in pixels.
323346 * @param {integer } tileHeight - The height of the tile in pixels.
347+ * @param {integer } baseWidth - The base width a tile in the map (in pixels).
348+ * @param {integer } baseHeight - The base height of the tile in pixels (in pixels).
349+ * @returns {this }
350+ */
351+ setSize : function ( tileWidth , tileHeight , baseWidth , baseHeight )
352+ {
353+ if ( tileWidth !== undefined ) { this . width = tileWidth ; }
354+ if ( tileHeight !== undefined ) { this . height = tileHeight ; }
355+ if ( baseWidth !== undefined ) { this . baseWidth = baseWidth ; }
356+ if ( baseHeight !== undefined ) { this . baseHeight = baseHeight ; }
357+
358+ this . updateWorldXY ( ) ;
359+
360+ return this ;
361+ } ,
362+
363+ /**
364+ * Used internally. Updates the tile's world XY position based on the current tile size.
365+ *
324366 * @returns {this }
325367 */
326- setSize : function ( tileWidth , tileHeight )
368+ updateWorldXY : function ( )
327369 {
328- this . worldX = this . x * tileWidth ;
329- this . worldY = this . y * tileHeight ;
330- this . width = tileWidth ;
331- this . height = tileHeight ;
370+ // Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the
371+ // bottom left, while the Phaser renderer assumes the origin is the top left. The y
372+ // coordinate needs to be adjusted by the difference.
373+ this . worldX = this . x * this . baseWidth ;
374+ this . worldY = this . y * this . baseHeight - ( this . height - this . baseHeight ) ;
332375
333376 return this ;
334377 } ,
0 commit comments