Skip to content

Commit 5a00a0a

Browse files
committed
TilemapParser will now throw a warning if the tileset image isn't the right size for the tile dimensions (fixes phaserjs#377)
1 parent 3ac8fba commit 5a00a0a

4 files changed

Lines changed: 82 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Updates:
137137
* Device, Canvas and GamePad classes all updated for better CocoonJS support (thanks Videlais)
138138
* BitmapData.alphaMask will draw the given image onto a BitmapData using an image as an alpha mask.
139139
* 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.
140+
* TilemapParser will now throw a warning if the tileset image isn't the right size for the tile dimensions.
140141

141142

142143
Bug Fixes:
@@ -154,6 +155,8 @@ Bug Fixes:
154155
* 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.
155156
* If pixelPerfect Input Sprites overlapped each other the pixel check wasn't taken into consieration in the Pointer move method.
156157
* Updated Input.Mouse to use event.button not event.which, so the const reference from input.mouse.button is correct (thanks grimor)
158+
* Text that was fixedToCamera would 'jitter' if the world scrolled. Now works as expected across all fixed objects.
159+
157160

158161

159162
TO DO:

labs/code/010 fixed to camera.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
3+
4+
function preload() {
5+
6+
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
7+
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
8+
game.load.image('coke', 'assets/sprites/cokecan.png');
9+
game.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml', null, 0, -32);
10+
11+
}
12+
13+
var cursors;
14+
var mushroom;
15+
16+
function create() {
17+
18+
game.world.setBounds(0, 0, 1920, 1200);
19+
game.add.image(0, 0, 'backdrop');
20+
21+
mushroom = game.add.sprite(400, 400, 'mushroom');
22+
23+
// Test Fixing an Image to the Camera
24+
var fixie = game.add.image(100, 100, 'coke');
25+
fixie.fixedToCamera = true;
26+
27+
// And tween it
28+
game.add.tween(fixie.cameraOffset).to({ y: 500 }, 2000, Phaser.Easing.Bounce.Out, true, 0, 1000, true);
29+
30+
// Test Fixing a Sprite to the Camera
31+
var fixie2 = game.add.sprite(600, 100, 'coke');
32+
fixie2.fixedToCamera = true;
33+
fixie2.inputEnabled = true;
34+
fixie2.input.enableDrag();
35+
36+
// Test Fixing a Text to the Camera
37+
var text = game.add.text(300, 32, 'arrows to move\ndrag the can ->');
38+
text.fixedToCamera = true;
39+
40+
// Test fixing a BitmapText to the Camera
41+
var text2 = game.add.bitmapText(270, 520, 'desyrel', 'Fixed to Camera!', 32);
42+
text2.fixedToCamera = true;
43+
44+
game.camera.follow(mushroom);
45+
46+
cursors = game.input.keyboard.createCursorKeys();
47+
48+
}
49+
50+
function update() {
51+
52+
if (cursors.left.isDown)
53+
{
54+
mushroom.x -= 8;
55+
}
56+
else if (cursors.right.isDown)
57+
{
58+
mushroom.x += 8;
59+
}
60+
61+
if (cursors.up.isDown)
62+
{
63+
mushroom.y -= 8;
64+
}
65+
else if (cursors.down.isDown)
66+
{
67+
mushroom.y += 8;
68+
}
69+
70+
}

src/gameobjects/BitmapData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Phaser.BitmapData.prototype = {
365365
if (this._dirty)
366366
{
367367
// Only needed if running in WebGL, otherwise this array will never get cleared down
368-
if (this.game.renderType == Phaser.WEBGL)
368+
if (this.game.renderType === Phaser.WEBGL)
369369
{
370370
PIXI.texturesToUpdate.push(this.baseTexture);
371371
}

src/tilemap/TilemapParser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,14 @@ Phaser.TilemapParser = {
400400
newSet.columns = (set.imagewidth - set.margin) / (set.tilewidth + set.spacing);
401401
newSet.total = newSet.rows * newSet.columns;
402402

403-
tilesets.push(newSet);
403+
if (newSet.rows % 1 !== 0 || newSet.columns % 1 !== 0)
404+
{
405+
console.warn('TileSet image dimensions do not match expected dimensions. Tileset width/height must be evenly divisible by Tilemap tile width/height.');
406+
}
407+
else
408+
{
409+
tilesets.push(newSet);
410+
}
404411
}
405412

406413
map.tilesets = tilesets;

0 commit comments

Comments
 (0)