diff --git a/examples/games/starstruck.php b/examples/games/starstruck.php index c3e1570d..8a1005ad 100644 --- a/examples/games/starstruck.php +++ b/examples/games/starstruck.php @@ -31,6 +31,7 @@ game.stage.backgroundColor = '#000000'; bg = game.add.tileSprite(0, 0, 800, 600, 'background'); + bg.fixedToCamera = true; map = game.add.tilemap(0, 0, 'level1'); map.setCollisionRange(1, 12, true, true, true, true); diff --git a/examples/tilemaps/mapcollide.php b/examples/tilemaps/mapcollide.php index d38fb888..1d71a887 100644 --- a/examples/tilemaps/mapcollide.php +++ b/examples/tilemaps/mapcollide.php @@ -1,5 +1,5 @@ @@ -16,6 +16,7 @@ var map; var p; + var cursors; function create() { @@ -31,42 +32,51 @@ p = game.add.sprite(32, 32, 'player'); + p.body.gravity.y = 10; p.body.bounce.y = 0.4; p.body.collideWorldBounds = true; + game.world.setBounds(0, 0, map.width, 600); + game.camera.follow(p); + cursors = game.input.keyboard.createCursorKeys(); + } function update() { - // map.collide(p); + map.collide(p); p.body.velocity.x = 0; - // p.body.acceleration.y = 500; - if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) - { - p.body.velocity.x = -150; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) - { - p.body.velocity.x = 150; - } - - if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + if (cursors.up.isDown) { if (p.body.touching.down) { - p.body.velocity.y = -200; + p.body.velocity.y = -400; } } + else if (cursors.down.isDown) + { + // game.camera.y += 4; + } + + if (cursors.left.isDown) + { + p.body.velocity.x = -150; + } + else if (cursors.right.isDown) + { + p.body.velocity.x = 150; + } } function render() { - game.debug.renderSpriteCorners(p); + game.debug.renderCameraInfo(game.camera, 32, 32); + // game.debug.renderSpriteCorners(p); game.debug.renderSpriteCollision(p, 32, 320); } diff --git a/examples/world/fixed to camera.php b/examples/world/fixed to camera.php index 03718a11..a3ab8dfe 100644 --- a/examples/world/fixed to camera.php +++ b/examples/world/fixed to camera.php @@ -71,10 +71,6 @@ window.onload = function () { function render() { game.debug.renderCameraInfo(game.camera, 32, 32); - // game.debug.renderSpriteInfo(d, 32, 200); - // game.debug.renderWorldTransformInfo(d, 32, 200); - // game.debug.renderLocalTransformInfo(d, 32, 400); - // game.debug.renderSpriteCorners(d, false, true); } diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 847ea55c..ad19fd81 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -71,6 +71,9 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) */ this.visible = true; + this.width = 0; + this.height = 0; + /** * @property {boolean} tiles - Description. * @default @@ -86,6 +89,7 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) var map = this.game.cache.getTilemap(key); PIXI.DisplayObjectContainer.call(this); + /** * @property {Description} position - Description. */ @@ -102,6 +106,8 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) */ this.renderer = new Phaser.TilemapRenderer(this.game); + this.fixedToCamera = true; + /** * @property {Description} mapFormat - Description. */ @@ -120,7 +126,7 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) if (this.currentLayer && resizeWorld) { - this.game.world.setBounds(0, 0, this.currentLayer.widthInPixels, this.currentLayer.heightInPixels); + this.game.world.setBounds(0, 0, this.width, this.heightIn); } }; @@ -169,6 +175,9 @@ Phaser.Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) this.collisionLayer = layer; this.layers.push(layer); + this.width = this.currentLayer.widthInPixels; + this.height = this.currentLayer.heightInPixels; + this.generateTiles(tileQuantity); }; @@ -227,6 +236,16 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) { this.currentLayer = layer; this.collisionLayer = layer; this.layers.push(layer); + + if (this.currentLayer.widthInPixels > this.width) + { + this.width = this.currentLayer.widthInPixels; + } + + if (this.currentLayer.heightInPixels > this.height) + { + this.height = this.currentLayer.heightInPixels; + } } this.generateTiles(tileQuantity); @@ -466,6 +485,14 @@ Phaser.Tilemap.prototype.update = function () { this.renderer.render(this); + if (this.fixedToCamera) + { + // this.displayObject.position.x = this.game.camera.view.x + this.x; + // this.displayObject.position.y = this.game.camera.view.y + this.y; + this.position.x = this.game.camera.view.x + 0; + this.position.y = this.game.camera.view.y + 0; + } + }; /**