Skip to content

Commit 3d22d0e

Browse files
committed
Fixed a bug in the tilemap rendering so the tile offsets were wrong. Now renders perfectly :) Also fixed issue that would cause the World to resize smaller than the game size (not allowed for rendering reasons).
1 parent 89b00db commit 3d22d0e

8 files changed

Lines changed: 180 additions & 23 deletions

File tree

examples/assets/maps/mario1.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{ "height":13,
2+
"layers":[
3+
{
4+
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1,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 1, 20, 1, 1, 1, 35, 35, 50, 35, 35, 1, 1, 37, 1, 43, 44, 51, 52, 45, 1, 1, 1, 1, 1, 1, 53, 54, 54, 54, 55, 43, 44, 45, 1, 56, 57, 1, 53, 54, 55, 1, 1, 38, 39, 1, 1, 1, 1, 1, 1, 1, 1, 38, 39, 58, 59, 54, 54, 55, 1, 38, 39, 43, 44, 60, 61, 62, 57, 63, 64, 1, 38, 39, 53, 54, 54, 54, 55, 43, 44, 45, 1, 1, 1, 1, 53, 54, 55, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 53, 54, 54, 55, 1, 65, 66, 67, 68, 60, 61, 45, 1, 1, 1, 1, 69, 70, 53, 54, 54, 54, 55, 43, 44, 45, 1, 1, 1, 1, 53, 54, 55, 1, 71, 72, 66, 65, 66, 58, 73, 1, 1, 1, 1, 19, 19, 19, 19, 54, 54, 19, 19, 19, 19, 43, 44, 60, 61, 19, 19, 19, 19, 19, 1, 1, 19, 19, 19, 19, 55, 43, 44, 45, 74, 75, 1, 1, 53, 54, 55, 1, 1, 1, 76, 77, 78, 1, 1, 1, 38, 39, 19, 19, 19, 19, 19, 19, 19, 19, 19, 1, 1, 43, 44, 60, 61, 45, 1, 19, 1, 1, 1, 35, 35, 79, 35, 35, 55, 43, 44, 45, 80, 80, 81, 82, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 83, 84, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 85, 86, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 83, 84, 87, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 1, 1, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 1, 1, 1, 80, 80, 80, 80, 80, 80, 88, 89, 90, 80, 80, 80, 80, 80, 80, 80, 91, 92, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 93, 94, 88, 80, 88, 85, 86, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 1, 1, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 95, 96, 97, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80],
5+
"height":13,
6+
"name":"ShoeBox Tile Grab",
7+
"opacity":1,
8+
"type":"tilelayer",
9+
"visible":true,
10+
"width":211,
11+
"x":0,
12+
"y":0
13+
}],
14+
"orientation":"orthogonal",
15+
"properties":
16+
{
17+
18+
},
19+
"tileheight":16,
20+
"tilesets":[
21+
{
22+
"firstgid":1,
23+
"image":"..\/..\/..\/..\/..\/..\/Art\/Artwork for game inspirations\/Super Mario Level Maps\/NES\/mario-1-1_bank.png",
24+
"imageheight":144,
25+
"imagewidth":176,
26+
"margin":0,
27+
"name":"mario-1-1_bank.png",
28+
"properties":
29+
{
30+
31+
},
32+
"spacing":0,
33+
"tileheight":16,
34+
"tilewidth":16
35+
}],
36+
"tilewidth":16,
37+
"version":1,
38+
"width":211
39+
}

examples/assets/maps/mario1.png

3.11 KB
Loading

examples/mario.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
16+
17+
function preload() {
18+
19+
// First we load our map data (a csv file)
20+
game.load.text('marioMap', 'assets/maps/mario1.json');
21+
22+
// Then we load the actual tile sheet image
23+
game.load.image('marioTiles', 'assets/maps/mario1.png');
24+
25+
}
26+
27+
var r;
28+
var t;
29+
30+
function create() {
31+
32+
game.stage.backgroundColor = '#787878';
33+
34+
// game, key, mapData, format, resizeWorld, tileWidth, tileHeight
35+
36+
// This creates the tilemap using the csv and tile sheet we loaded.
37+
// We tell it use to CSV format parser. The 16x16 are the tile sizes.
38+
// The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not.
39+
40+
t = new Phaser.Tilemap(game, 'marioTiles', 'marioMap', Phaser.Tilemap.FORMAT_TILED_JSON);
41+
42+
// SHould be added to the World and rendered automatically :)
43+
r = new Phaser.TilemapRenderer(game);
44+
45+
}
46+
47+
function update() {
48+
49+
r.render(t);
50+
51+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
52+
{
53+
game.camera.x -= 8;
54+
}
55+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
56+
{
57+
game.camera.x += 8;
58+
}
59+
60+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
61+
{
62+
game.camera.y -= 8;
63+
}
64+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
65+
{
66+
game.camera.y += 8;
67+
}
68+
69+
}
70+
71+
function render() {
72+
}
73+
74+
})();
75+
</script>
76+
77+
</body>
78+
</html>

examples/tilemap.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function create() {
4444

4545
t = new Phaser.Tilemap(game, 'csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16);
4646

47+
// SHould be added to the World and rendered automatically :)
4748
r = new Phaser.TilemapRenderer(game);
4849

4950
}
@@ -54,20 +55,20 @@ function update() {
5455

5556
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
5657
{
57-
game.camera.x -= 4;
58+
game.camera.x -= 8;
5859
}
5960
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
6061
{
61-
game.camera.x += 4;
62+
game.camera.x += 8;
6263
}
6364

6465
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
6566
{
66-
game.camera.y -= 4;
67+
game.camera.y -= 8;
6768
}
6869
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
6970
{
70-
game.camera.y += 4;
71+
game.camera.y += 8;
7172
}
7273

7374
}

src/core/World.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,15 @@ Phaser.World.prototype = {
9797
*/
9898
setSize: function (width, height) {
9999

100-
this.bounds.width = width;
101-
this.bounds.height = height;
100+
if (width >= this.game.width)
101+
{
102+
this.bounds.width = width;
103+
}
104+
105+
if (height >= this.game.height)
106+
{
107+
this.bounds.height = height;
108+
}
102109

103110
}
104111

src/tilemap/Tilemap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Phaser.Tilemap.prototype = {
100100
}
101101

102102
layer.updateBounds();
103+
layer.createCanvas();
103104

104105
var tileQuantity = layer.parseTileOffsets();
105106

@@ -159,6 +160,7 @@ Phaser.Tilemap.prototype = {
159160
}
160161

161162
layer.updateBounds();
163+
layer.createCanvas();
162164

163165
var tileQuantity = layer.parseTileOffsets();
164166

src/tilemap/TilemapLayer.js

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,23 @@ Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, til
8282

8383
this.tileset = this.game.cache.getImage(key);
8484

85+
// Sprite property surely?
8586
this.alpha = 1;
86-
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height);
87-
this.context = this.canvas.getContext('2d');
88-
this.baseTexture = new PIXI.BaseTexture(this.canvas);
89-
this.texture = new PIXI.Texture(this.baseTexture);
90-
this.sprite = new PIXI.Sprite(this.texture);
91-
this.game.stage._stage.addChild(this.sprite);
87+
88+
this.canvas = null;
89+
this.context = null;
90+
this.baseTexture = null;
91+
this.texture = null;
92+
this.sprite = null;
93+
94+
// this.canvas = Phaser.Canvas.create(this.game.width, this.game.height);
95+
// this.context = this.canvas.getContext('2d');
96+
97+
// this.baseTexture = new PIXI.BaseTexture(this.canvas);
98+
// this.texture = new PIXI.Texture(this.baseTexture);
99+
// this.sprite = new PIXI.Sprite(this.texture);
100+
101+
// this.game.stage._stage.addChild(this.sprite);
92102

93103
this.mapData = [];
94104
this._tempTileBlock = [];
@@ -443,6 +453,32 @@ Phaser.TilemapLayer.prototype = {
443453
this.heightInTiles++;
444454
this.heightInPixels += this.tileHeight;
445455

456+
},
457+
458+
createCanvas: function () {
459+
460+
var width = this.game.width;
461+
var height = this.game.height;
462+
463+
if (this.widthInPixels < width)
464+
{
465+
width = this.widthInPixels;
466+
}
467+
468+
if (this.heightInPixels < height)
469+
{
470+
height = this.heightInPixels;
471+
}
472+
473+
this.canvas = Phaser.Canvas.create(width, height);
474+
this.context = this.canvas.getContext('2d');
475+
476+
this.baseTexture = new PIXI.BaseTexture(this.canvas);
477+
this.texture = new PIXI.Texture(this.baseTexture);
478+
this.sprite = new PIXI.Sprite(this.texture);
479+
480+
this.game.stage._stage.addChild(this.sprite);
481+
446482
},
447483

448484
/**
@@ -456,6 +492,9 @@ Phaser.TilemapLayer.prototype = {
456492

457493
/**
458494
* Parse tile offsets from map data.
495+
* Basically this creates a large array of objects that contain the x/y coordinates to grab each tile from
496+
* for the entire map. Yes we could calculate this at run-time by using the tile index and some math, but we're
497+
* trading a quite small bit of memory here to not have to process that in our main render loop.
459498
* @return {number} length of tileOffsets array.
460499
*/
461500
parseTileOffsets: function () {

src/tilemap/TilemapRenderer.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ Phaser.TilemapRenderer.prototype = {
4343
this._maxY = this.game.math.ceil(layer.canvas.height / layer.tileHeight) + 1;
4444

4545
// And now work out where in the tilemap the camera actually is
46-
// this._startX = this.game.math.floor(camera.worldView.x / layer.tileWidth);
47-
// this._startY = this.game.math.floor(camera.worldView.y / layer.tileHeight);
4846
this._startX = this.game.math.floor(this.game.camera.x / layer.tileWidth);
4947
this._startY = this.game.math.floor(this.game.camera.y / layer.tileHeight);
5048

@@ -80,15 +78,8 @@ Phaser.TilemapRenderer.prototype = {
8078
}
8179

8280
// Finally get the offset to avoid the blocky movement
83-
//this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x);
84-
//this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y);
85-
//this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x);
86-
//this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y);
87-
this._dx = 0;
88-
this._dy = 0;
89-
90-
this._dx += -(this.game.camera.x - (this._startX * layer.tileWidth));
91-
this._dy += -(this.game.camera.y - (this._startY * layer.tileHeight));
81+
this._dx = -(this.game.camera.x - (this._startX * layer.tileWidth));
82+
this._dy = -(this.game.camera.y - (this._startY * layer.tileHeight));
9283

9384
this._tx = this._dx;
9485
this._ty = this._dy;

0 commit comments

Comments
 (0)