Skip to content

Commit fa69265

Browse files
committed
Final commit before rebuilding the Tilemap system.
1 parent c307f79 commit fa69265

4 files changed

Lines changed: 52 additions & 18 deletions

File tree

examples/games/starstruck.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function create() {
3131
game.stage.backgroundColor = '#000000';
3232

3333
bg = game.add.tileSprite(0, 0, 800, 600, 'background');
34+
bg.fixedToCamera = true;
3435

3536
map = game.add.tilemap(0, 0, 'level1');
3637
map.setCollisionRange(1, 12, true, true, true, true);

examples/tilemaps/mapcollide.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$title = "Test Title";
2+
$title = "Tilemap Collision";
33
require('../head.php');
44
?>
55

@@ -16,6 +16,7 @@ function preload() {
1616

1717
var map;
1818
var p;
19+
var cursors;
1920

2021
function create() {
2122

@@ -31,42 +32,51 @@ function create() {
3132

3233
p = game.add.sprite(32, 32, 'player');
3334

35+
p.body.gravity.y = 10;
3436
p.body.bounce.y = 0.4;
3537
p.body.collideWorldBounds = true;
3638

39+
game.world.setBounds(0, 0, map.width, 600);
40+
3741
game.camera.follow(p);
3842

43+
cursors = game.input.keyboard.createCursorKeys();
44+
3945
}
4046

4147
function update() {
4248

43-
// map.collide(p);
49+
map.collide(p);
4450

4551
p.body.velocity.x = 0;
46-
// p.body.acceleration.y = 500;
4752

48-
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
53+
if (cursors.up.isDown)
4954
{
50-
p.body.velocity.x = -150;
55+
if (p.body.touching.down)
56+
{
57+
p.body.velocity.y = -400;
58+
}
5159
}
52-
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
60+
else if (cursors.down.isDown)
5361
{
54-
p.body.velocity.x = 150;
62+
// game.camera.y += 4;
5563
}
5664

57-
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
65+
if (cursors.left.isDown)
5866
{
59-
if (p.body.touching.down)
60-
{
61-
p.body.velocity.y = -200;
62-
}
67+
p.body.velocity.x = -150;
68+
}
69+
else if (cursors.right.isDown)
70+
{
71+
p.body.velocity.x = 150;
6372
}
6473

6574
}
6675

6776
function render() {
6877

69-
game.debug.renderSpriteCorners(p);
78+
game.debug.renderCameraInfo(game.camera, 32, 32);
79+
// game.debug.renderSpriteCorners(p);
7080
game.debug.renderSpriteCollision(p, 32, 320);
7181

7282
}

examples/world/fixed to camera.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ function update() {
7171
function render() {
7272

7373
game.debug.renderCameraInfo(game.camera, 32, 32);
74-
// game.debug.renderSpriteInfo(d, 32, 200);
75-
// game.debug.renderWorldTransformInfo(d, 32, 200);
76-
// game.debug.renderLocalTransformInfo(d, 32, 400);
77-
// game.debug.renderSpriteCorners(d, false, true);
7874

7975
}
8076

src/tilemap/Tilemap.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight)
7171
*/
7272
this.visible = true;
7373

74+
this.width = 0;
75+
this.height = 0;
76+
7477
/**
7578
* @property {boolean} tiles - Description.
7679
* @default
@@ -86,6 +89,7 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight)
8689
var map = this.game.cache.getTilemap(key);
8790

8891
PIXI.DisplayObjectContainer.call(this);
92+
8993
/**
9094
* @property {Description} position - Description.
9195
*/
@@ -102,6 +106,8 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight)
102106
*/
103107
this.renderer = new Phaser.TilemapRenderer(this.game);
104108

109+
this.fixedToCamera = true;
110+
105111
/**
106112
* @property {Description} mapFormat - Description.
107113
*/
@@ -120,7 +126,7 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight)
120126

121127
if (this.currentLayer && resizeWorld)
122128
{
123-
this.game.world.setBounds(0, 0, this.currentLayer.widthInPixels, this.currentLayer.heightInPixels);
129+
this.game.world.setBounds(0, 0, this.width, this.heightIn);
124130
}
125131

126132
};
@@ -169,6 +175,9 @@ Phaser.Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight)
169175
this.collisionLayer = layer;
170176
this.layers.push(layer);
171177

178+
this.width = this.currentLayer.widthInPixels;
179+
this.height = this.currentLayer.heightInPixels;
180+
172181
this.generateTiles(tileQuantity);
173182

174183
};
@@ -227,6 +236,16 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) {
227236
this.currentLayer = layer;
228237
this.collisionLayer = layer;
229238
this.layers.push(layer);
239+
240+
if (this.currentLayer.widthInPixels > this.width)
241+
{
242+
this.width = this.currentLayer.widthInPixels;
243+
}
244+
245+
if (this.currentLayer.heightInPixels > this.height)
246+
{
247+
this.height = this.currentLayer.heightInPixels;
248+
}
230249
}
231250

232251
this.generateTiles(tileQuantity);
@@ -466,6 +485,14 @@ Phaser.Tilemap.prototype.update = function () {
466485

467486
this.renderer.render(this);
468487

488+
if (this.fixedToCamera)
489+
{
490+
// this.displayObject.position.x = this.game.camera.view.x + this.x;
491+
// this.displayObject.position.y = this.game.camera.view.y + this.y;
492+
this.position.x = this.game.camera.view.x + 0;
493+
this.position.y = this.game.camera.view.y + 0;
494+
}
495+
469496
};
470497

471498
/**

0 commit comments

Comments
 (0)