From 5a00a0ad97d86623ef147d3b54b70294b1082ca0 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 21 Feb 2014 16:57:45 +0000 Subject: [PATCH] TilemapParser will now throw a warning if the tileset image isn't the right size for the tile dimensions (fixes #377) --- README.md | 3 ++ labs/code/010 fixed to camera.js | 70 ++++++++++++++++++++++++++++++++ src/gameobjects/BitmapData.js | 2 +- src/tilemap/TilemapParser.js | 9 +++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 labs/code/010 fixed to camera.js diff --git a/README.md b/README.md index e5663203..89afd9b3 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ Updates: * Device, Canvas and GamePad classes all updated for better CocoonJS support (thanks Videlais) * BitmapData.alphaMask will draw the given image onto a BitmapData using an image as an alpha mask. * The new GameObjectCreator (which you access via game.make or State.make) lets you easily create an object but NOT add it to the display list. +* TilemapParser will now throw a warning if the tileset image isn't the right size for the tile dimensions. Bug Fixes: @@ -154,6 +155,8 @@ Bug Fixes: * Previously using a Pixel Perfect check didn't work if the Sprite was rotated or had a non-zero anchor point, now works under all conditions + atlas frames. * If pixelPerfect Input Sprites overlapped each other the pixel check wasn't taken into consieration in the Pointer move method. * Updated Input.Mouse to use event.button not event.which, so the const reference from input.mouse.button is correct (thanks grimor) +* Text that was fixedToCamera would 'jitter' if the world scrolled. Now works as expected across all fixed objects. + TO DO: diff --git a/labs/code/010 fixed to camera.js b/labs/code/010 fixed to camera.js new file mode 100644 index 00000000..d900f3ef --- /dev/null +++ b/labs/code/010 fixed to camera.js @@ -0,0 +1,70 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + game.load.image('coke', 'assets/sprites/cokecan.png'); + game.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml', null, 0, -32); + +} + +var cursors; +var mushroom; + +function create() { + + game.world.setBounds(0, 0, 1920, 1200); + game.add.image(0, 0, 'backdrop'); + + mushroom = game.add.sprite(400, 400, 'mushroom'); + + // Test Fixing an Image to the Camera + var fixie = game.add.image(100, 100, 'coke'); + fixie.fixedToCamera = true; + + // And tween it + game.add.tween(fixie.cameraOffset).to({ y: 500 }, 2000, Phaser.Easing.Bounce.Out, true, 0, 1000, true); + + // Test Fixing a Sprite to the Camera + var fixie2 = game.add.sprite(600, 100, 'coke'); + fixie2.fixedToCamera = true; + fixie2.inputEnabled = true; + fixie2.input.enableDrag(); + + // Test Fixing a Text to the Camera + var text = game.add.text(300, 32, 'arrows to move\ndrag the can ->'); + text.fixedToCamera = true; + + // Test fixing a BitmapText to the Camera + var text2 = game.add.bitmapText(270, 520, 'desyrel', 'Fixed to Camera!', 32); + text2.fixedToCamera = true; + + game.camera.follow(mushroom); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function update() { + + if (cursors.left.isDown) + { + mushroom.x -= 8; + } + else if (cursors.right.isDown) + { + mushroom.x += 8; + } + + if (cursors.up.isDown) + { + mushroom.y -= 8; + } + else if (cursors.down.isDown) + { + mushroom.y += 8; + } + +} diff --git a/src/gameobjects/BitmapData.js b/src/gameobjects/BitmapData.js index 7a3d313f..9fdcc462 100644 --- a/src/gameobjects/BitmapData.js +++ b/src/gameobjects/BitmapData.js @@ -365,7 +365,7 @@ Phaser.BitmapData.prototype = { if (this._dirty) { // Only needed if running in WebGL, otherwise this array will never get cleared down - if (this.game.renderType == Phaser.WEBGL) + if (this.game.renderType === Phaser.WEBGL) { PIXI.texturesToUpdate.push(this.baseTexture); } diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js index f3691eb0..973e3917 100644 --- a/src/tilemap/TilemapParser.js +++ b/src/tilemap/TilemapParser.js @@ -400,7 +400,14 @@ Phaser.TilemapParser = { newSet.columns = (set.imagewidth - set.margin) / (set.tilewidth + set.spacing); newSet.total = newSet.rows * newSet.columns; - tilesets.push(newSet); + if (newSet.rows % 1 !== 0 || newSet.columns % 1 !== 0) + { + console.warn('TileSet image dimensions do not match expected dimensions. Tileset width/height must be evenly divisible by Tilemap tile width/height.'); + } + else + { + tilesets.push(newSet); + } } map.tilesets = tilesets;