diff --git a/examples/assets/maps/mario1.json b/examples/assets/maps/mario1.json new file mode 100644 index 000000000..ffff33bb3 --- /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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 19, 19, 1, 1, 19, 19, 1, 1, 1, 1, 37, 1, 1, 1, 19, 19, 19, 1, 1, 19, 19, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 19, 19, 19, 19, 19, 19, 19, 1, 1, 1, 1, 37, 1, 1, 1, 20, 1, 1, 1, 31, 42, 42, 42, 31, 1, 1, 1, 1, 1, 43, 44, 45, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 32, 33, 1, 1, 1, 1, 1, 1, 1, 1, 38, 39, 1, 1, 1, 1, 1, 1, 38, 39, 1, 43, 44, 45, 1, 1, 1, 1, 1, 46, 47, 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, 1, 1, 1, 1, 1, 1, 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 000000000..9cc96c175 Binary files /dev/null and b/examples/assets/maps/mario1.png differ diff --git a/examples/mario.php b/examples/mario.php new file mode 100644 index 000000000..6205bd1c2 --- /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 e09ec8c4f..f34175664 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 8b9a775b4..353be1254 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 a70b71288..a05861a8e 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 cea29098c..15228e790 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 240754500..964a3db6c 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;