Skip to content

Commit 742ff1a

Browse files
committed
Internal terminology change to make API clearer: tile.worldXY -> tile.pixelXY
1 parent 3a0c276 commit 742ff1a

7 files changed

Lines changed: 33 additions & 31 deletions

File tree

v3/src/gameobjects/tilemap/Tile.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,22 @@ var Tile = new Class({
8686
this.baseHeight = (baseHeight !== undefined) ? baseHeight : height;
8787

8888
/**
89-
* The world x coordinate of the top left of this tile in pixels. This does not factor in
90-
* camera scroll, layer scale or layer position.
91-
* @property {number} x
89+
* The x coordinate of the top left of this tile in pixels. This is relative to the top left
90+
* of the layer this tile is being rendered within. This property does NOT factor in camera
91+
* scroll, layer scale or layer position.
92+
* @property {number} pixelX
9293
*/
93-
this.worldX = 0;
94+
this.pixelX = 0;
9495

9596
/**
96-
* The world y coordinate of the top left of this tile in pixels. This does not factor in
97-
* camera scroll, layer scale or layer position.
98-
* @property {number} y
97+
* The y coordinate of the top left of this tile in pixels. This is relative to the top left
98+
* of the layer this tile is being rendered within. This property does NOT factor in camera
99+
* scroll, layer scale or layer position.
100+
* @property {number} pixelY
99101
*/
100-
this.worldY = 0;
102+
this.pixelY = 0;
101103

102-
this.updateWorldXY();
104+
this.updatePixelXY();
103105

104106
/**
105107
* Tile specific properties. These usually come from Tiled.
@@ -192,7 +194,7 @@ var Tile = new Class({
192194
*/
193195
containsPoint: function (x, y)
194196
{
195-
return !(x < this.worldX || y < this.worldY || x > this.right || y > this.bottom);
197+
return !(x < this.pixelX || y < this.pixelY || x > this.right || y > this.bottom);
196198
},
197199

198200
/**
@@ -244,7 +246,7 @@ var Tile = new Class({
244246
intersects: function (x, y, right, bottom)
245247
{
246248
return !(
247-
right <= this.worldX || bottom <= this.worldY ||
249+
right <= this.pixelX || bottom <= this.pixelY ||
248250
x >= this.right || y >= this.bottom
249251
);
250252
},
@@ -354,7 +356,7 @@ var Tile = new Class({
354356
},
355357

356358
/**
357-
* Sets the size of the tile and updates its worldX and worldY.
359+
* Sets the size of the tile and updates its pixelX and pixelY.
358360
*
359361
* @param {integer} tileWidth - The width of the tile in pixels.
360362
* @param {integer} tileHeight - The height of the tile in pixels.
@@ -369,7 +371,7 @@ var Tile = new Class({
369371
if (baseWidth !== undefined) { this.baseWidth = baseWidth; }
370372
if (baseHeight !== undefined) { this.baseHeight = baseHeight; }
371373

372-
this.updateWorldXY();
374+
this.updatePixelXY();
373375

374376
return this;
375377
},
@@ -379,13 +381,13 @@ var Tile = new Class({
379381
*
380382
* @returns {this}
381383
*/
382-
updateWorldXY: function ()
384+
updatePixelXY: function ()
383385
{
384386
// Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the
385387
// bottom left, while the Phaser renderer assumes the origin is the top left. The y
386388
// coordinate needs to be adjusted by the difference.
387-
this.worldX = this.x * this.baseWidth;
388-
this.worldY = this.y * this.baseHeight - (this.height - this.baseHeight);
389+
this.pixelX = this.x * this.baseWidth;
390+
this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
389391

390392
return this;
391393
},
@@ -435,7 +437,7 @@ var Tile = new Class({
435437
left: {
436438
get: function ()
437439
{
438-
return this.worldX;
440+
return this.pixelX;
439441
}
440442
},
441443

@@ -448,7 +450,7 @@ var Tile = new Class({
448450
right: {
449451
get: function ()
450452
{
451-
return this.worldX + this.width;
453+
return this.pixelX + this.width;
452454
}
453455
},
454456

@@ -461,7 +463,7 @@ var Tile = new Class({
461463
top: {
462464
get: function ()
463465
{
464-
return this.worldY;
466+
return this.pixelY;
465467
}
466468
},
467469

@@ -474,7 +476,7 @@ var Tile = new Class({
474476
bottom: {
475477
get: function ()
476478
{
477-
return this.worldY + this.height;
479+
return this.pixelY + this.height;
478480
}
479481
},
480482

@@ -487,7 +489,7 @@ var Tile = new Class({
487489
centerX: {
488490
get: function ()
489491
{
490-
return this.worldX + this.width / 2;
492+
return this.pixelX + this.width / 2;
491493
}
492494
},
493495

@@ -500,7 +502,7 @@ var Tile = new Class({
500502
centerY: {
501503
get: function ()
502504
{
503-
return this.worldY + this.height / 2;
505+
return this.pixelY + this.height / 2;
504506
}
505507
}
506508

v3/src/gameobjects/tilemap/components/CullTiles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ var CullTiles = function (layer, camera, outputArray)
3232

3333
if (tile === null || (tile.index <= 0 && tilemapLayer.skipIndexZero)) { continue; }
3434

35-
var tileX = tile.worldX * sx - left;
36-
var tileY = tile.worldY * sy - top;
35+
var tileX = tile.pixelX * sx - left;
36+
var tileY = tile.pixelY * sy - top;
3737
var cullW = camera.width + tileWidth;
3838
var cullH = camera.height + tileHeight;
3939

v3/src/gameobjects/tilemap/components/RenderDebug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var RenderDebug = function (graphics, styleConfig, layer)
4040

4141
var tw = tile.width;
4242
var th = tile.height;
43-
var x = tile.worldX;
44-
var y = tile.worldY;
43+
var x = tile.pixelX;
44+
var y = tile.pixelY;
4545

4646
var color = tile.collides ? collidingTileColor : tileColor;
4747
if (color !== null)

v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, gameObject, interpol
3535
var halfHeight = tile.height / 2;
3636

3737
ctx.save();
38-
ctx.translate(tile.worldX + halfWidth, tile.worldY + halfHeight);
38+
ctx.translate(tile.pixelX + halfWidth, tile.pixelY + halfHeight);
3939

4040
if (tile.flipX || tile.flipY)
4141
{

v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerWebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, gameObject, interpola
3939

4040
batch.addTileTextureRect(
4141
texture,
42-
x + tile.worldX * sx, y + tile.worldY * sy,
42+
x + tile.pixelX * sx, y + tile.pixelY * sy,
4343
tile.width * sx, tile.height * sy,
4444
alpha * tile.alpha, tile.tint,
4545
scrollFactorX, scrollFactorY,

v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ var StaticTilemapLayer = new Class({
168168
tile = mapData[row][col];
169169
if (tile === null || (tile.index <= 0 && this.skipIndexZero)) { continue; }
170170

171-
var tx = tile.worldX;
172-
var ty = tile.worldY;
171+
var tx = tile.pixelX;
172+
var ty = tile.pixelY;
173173
var txw = tx + tile.width;
174174
var tyh = ty + tile.height;
175175

v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayerCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var StaticTilemapLayerCanvasRenderer = function (renderer, gameObject, interpola
3737
image,
3838
tileTexCoords.x, tileTexCoords.y,
3939
tile.width, tile.height,
40-
tile.worldX, tile.worldY,
40+
tile.pixelX, tile.pixelY,
4141
tile.width, tile.height
4242
);
4343
}

0 commit comments

Comments
 (0)