From 3d22d0e16914a6bb3e4bb007f63106b214159f27 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 12 Sep 2013 02:18:23 +0100 Subject: [PATCH] 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). --- examples/assets/maps/mario1.json | 39 ++++++++++++++++ examples/assets/maps/mario1.png | Bin 0 -> 3181 bytes examples/mario.php | 78 +++++++++++++++++++++++++++++++ examples/tilemap.php | 9 ++-- src/core/World.js | 11 ++++- src/tilemap/Tilemap.js | 2 + src/tilemap/TilemapLayer.js | 51 +++++++++++++++++--- src/tilemap/TilemapRenderer.js | 13 +----- 8 files changed, 180 insertions(+), 23 deletions(-) create mode 100644 examples/assets/maps/mario1.json create mode 100644 examples/assets/maps/mario1.png create mode 100644 examples/mario.php diff --git a/examples/assets/maps/mario1.json b/examples/assets/maps/mario1.json new file mode 100644 index 00000000..ffff33bb --- /dev/null +++ b/examples/assets/maps/mario1.json @@ -0,0 +1,39 @@ +{ "height":13, + "layers":[ + { + "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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, 1, 1, 1, 1, 43, 44, 45, 1, 1, 1, 1, 1, 48, 49, 1, 1, 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 19, 19, 19, 1, 1, 19, 19, 19, 1, 1, 43, 44, 45, 1, 19, 19, 19, 19, 1, 1, 19, 19, 19, 1, 1, 1, 37, 1, 32, 33, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 32, 33, 1, 19, 19, 19, 19, 19, 19, 19, 19, 1, 1, 1, 43, 44, 45, 1, 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], + "height":13, + "name":"ShoeBox Tile Grab", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":211, + "x":0, + "y":0 + }], + "orientation":"orthogonal", + "properties": + { + + }, + "tileheight":16, + "tilesets":[ + { + "firstgid":1, + "image":"..\/..\/..\/..\/..\/..\/Art\/Artwork for game inspirations\/Super Mario Level Maps\/NES\/mario-1-1_bank.png", + "imageheight":144, + "imagewidth":176, + "margin":0, + "name":"mario-1-1_bank.png", + "properties": + { + + }, + "spacing":0, + "tileheight":16, + "tilewidth":16 + }], + "tilewidth":16, + "version":1, + "width":211 +} \ No newline at end of file diff --git a/examples/assets/maps/mario1.png b/examples/assets/maps/mario1.png new file mode 100644 index 0000000000000000000000000000000000000000..9cc96c1754be7a6c91c88dccafe3cbc90becb301 GIT binary patch literal 3181 zcmV-z43hJSP)y=xWC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TlqEY9a=2BdH}tju-aV zvQM*mR*9w*s;8}q*;}@Q_fhJXv;p`2sk&iG`%~_xcl~MgzsN&|y(kYG0Ec}58~}%X z033SMuxIFTcL6x`sA1p8AnoIULysEvH9c;`z+oRTZ~z?k0dRC+*zX2#=uyL7XusYA zhaNTT*?L?rAw=j=!=9zb^%et%9yRPqdR)(gxX`19{Y3n{_Fw2x!(ODvUHtDqa+@>! TaiH#c00000NkvXXu0mjfU@!Dv literal 0 HcmV?d00001 diff --git a/examples/mario.php b/examples/mario.php new file mode 100644 index 00000000..6205bd1c --- /dev/null +++ b/examples/mario.php @@ -0,0 +1,78 @@ + + + + phaser.js - a new beginning + + + + + + + + \ No newline at end of file diff --git a/examples/tilemap.php b/examples/tilemap.php index e09ec8c4..f3417566 100644 --- a/examples/tilemap.php +++ b/examples/tilemap.php @@ -44,6 +44,7 @@ t = new Phaser.Tilemap(game, 'csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16); + // SHould be added to the World and rendered automatically :) r = new Phaser.TilemapRenderer(game); } @@ -54,20 +55,20 @@ if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { - game.camera.x -= 4; + game.camera.x -= 8; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { - game.camera.x += 4; + game.camera.x += 8; } if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { - game.camera.y -= 4; + game.camera.y -= 8; } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { - game.camera.y += 4; + game.camera.y += 8; } } diff --git a/src/core/World.js b/src/core/World.js index 8b9a775b..353be125 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -97,8 +97,15 @@ Phaser.World.prototype = { */ setSize: function (width, height) { - this.bounds.width = width; - this.bounds.height = height; + if (width >= this.game.width) + { + this.bounds.width = width; + } + + if (height >= this.game.height) + { + this.bounds.height = height; + } } diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index a70b7128..a05861a8 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -100,6 +100,7 @@ Phaser.Tilemap.prototype = { } layer.updateBounds(); + layer.createCanvas(); var tileQuantity = layer.parseTileOffsets(); @@ -159,6 +160,7 @@ Phaser.Tilemap.prototype = { } layer.updateBounds(); + layer.createCanvas(); var tileQuantity = layer.parseTileOffsets(); diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index cea29098..15228e79 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -82,13 +82,23 @@ Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, til this.tileset = this.game.cache.getImage(key); + // Sprite property surely? this.alpha = 1; - this.canvas = Phaser.Canvas.create(this.game.width, this.game.height); - this.context = this.canvas.getContext('2d'); - this.baseTexture = new PIXI.BaseTexture(this.canvas); - this.texture = new PIXI.Texture(this.baseTexture); - this.sprite = new PIXI.Sprite(this.texture); - this.game.stage._stage.addChild(this.sprite); + + this.canvas = null; + this.context = null; + this.baseTexture = null; + this.texture = null; + this.sprite = null; + + // this.canvas = Phaser.Canvas.create(this.game.width, this.game.height); + // this.context = this.canvas.getContext('2d'); + + // this.baseTexture = new PIXI.BaseTexture(this.canvas); + // this.texture = new PIXI.Texture(this.baseTexture); + // this.sprite = new PIXI.Sprite(this.texture); + + // this.game.stage._stage.addChild(this.sprite); this.mapData = []; this._tempTileBlock = []; @@ -443,6 +453,32 @@ Phaser.TilemapLayer.prototype = { this.heightInTiles++; this.heightInPixels += this.tileHeight; + }, + + createCanvas: function () { + + var width = this.game.width; + var height = this.game.height; + + if (this.widthInPixels < width) + { + width = this.widthInPixels; + } + + if (this.heightInPixels < height) + { + height = this.heightInPixels; + } + + this.canvas = Phaser.Canvas.create(width, height); + this.context = this.canvas.getContext('2d'); + + this.baseTexture = new PIXI.BaseTexture(this.canvas); + this.texture = new PIXI.Texture(this.baseTexture); + this.sprite = new PIXI.Sprite(this.texture); + + this.game.stage._stage.addChild(this.sprite); + }, /** @@ -456,6 +492,9 @@ Phaser.TilemapLayer.prototype = { /** * Parse tile offsets from map data. + * Basically this creates a large array of objects that contain the x/y coordinates to grab each tile from + * for the entire map. Yes we could calculate this at run-time by using the tile index and some math, but we're + * trading a quite small bit of memory here to not have to process that in our main render loop. * @return {number} length of tileOffsets array. */ parseTileOffsets: function () { diff --git a/src/tilemap/TilemapRenderer.js b/src/tilemap/TilemapRenderer.js index 24075450..964a3db6 100644 --- a/src/tilemap/TilemapRenderer.js +++ b/src/tilemap/TilemapRenderer.js @@ -43,8 +43,6 @@ Phaser.TilemapRenderer.prototype = { this._maxY = this.game.math.ceil(layer.canvas.height / layer.tileHeight) + 1; // And now work out where in the tilemap the camera actually is - // this._startX = this.game.math.floor(camera.worldView.x / layer.tileWidth); - // this._startY = this.game.math.floor(camera.worldView.y / layer.tileHeight); this._startX = this.game.math.floor(this.game.camera.x / layer.tileWidth); this._startY = this.game.math.floor(this.game.camera.y / layer.tileHeight); @@ -80,15 +78,8 @@ Phaser.TilemapRenderer.prototype = { } // Finally get the offset to avoid the blocky movement - //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x); - //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y); - //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x); - //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y); - this._dx = 0; - this._dy = 0; - - this._dx += -(this.game.camera.x - (this._startX * layer.tileWidth)); - this._dy += -(this.game.camera.y - (this._startY * layer.tileHeight)); + this._dx = -(this.game.camera.x - (this._startX * layer.tileWidth)); + this._dy = -(this.game.camera.y - (this._startY * layer.tileHeight)); this._tx = this._dx; this._ty = this._dy;