Skip to content

Commit

Permalink
Fixed all the tilemap examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Mar 14, 2014
1 parent d2506dd commit f3ff9c1
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 263 deletions.
20 changes: 11 additions & 9 deletions examples/tilemaps/create from objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ function create() {

layer = map.createLayer('Tile Layer 1');

// layer.debug = true;

layer.resizeWorld();

game.physics.startSystem(Phaser.Physics.ARCADE);

// Here we create our coins group
coins = game.add.group();
coins.enableBody = true;

// And now we convert all of the Tiled objects with an ID of 34 into sprites within the coins group
map.createFromObjects('Object Layer 1', 34, 'coin', 0, true, false, coins);
Expand All @@ -48,10 +49,12 @@ function create() {
coins.callAll('animations.play', 'animations', 'spin');

sprite = game.add.sprite(260, 100, 'phaser');
sprite.anchor.setTo(0.5, 0.5);
sprite.anchor.set(0.5);

game.physics.arcade.enable(sprite);

// This adjusts the collision body size.
sprite.body.setRectangle(16, 16, 25, 15);
sprite.body.setSize(32, 32, 16, 16);

// We'll set a lower max angular velocity here to keep it from going totally nuts
sprite.body.maxAngular = 500;
Expand All @@ -67,8 +70,8 @@ function create() {

function update() {

game.physics.collide(sprite, layer);
game.physics.overlap(sprite, coins, collectCoin, null, this);
game.physics.arcade.collide(sprite, layer);
game.physics.arcade.overlap(sprite, coins, collectCoin, null, this);

sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
Expand All @@ -85,10 +88,9 @@ function update() {

if (cursors.up.isDown)
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
game.physics.arcade.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}


}

function collectCoin(player, coin) {
Expand All @@ -99,6 +101,6 @@ function collectCoin(player, coin) {

function render() {

game.debug.physicsBody(sprite.body);
game.debug.body(sprite);

}
8 changes: 6 additions & 2 deletions examples/tilemaps/fill tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var sprite;

function create() {

game.physics.startSystem(Phaser.Physics.ARCADE);

map = game.add.tilemap('desert');

map.addTilesetImage('Desert', 'tiles');
Expand All @@ -28,6 +30,8 @@ function create() {
sprite = game.add.sprite(450, 80, 'car');
sprite.anchor.setTo(0.5, 0.5);

game.physics.enable(sprite);

game.camera.follow(sprite);

cursors = game.input.keyboard.createCursorKeys();
Expand All @@ -44,7 +48,7 @@ function fillTiles() {

function update() {

game.physics.collide(sprite, layer);
game.physics.arcade.collide(sprite, layer);

sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
Expand All @@ -61,7 +65,7 @@ function update() {

if (cursors.up.isDown)
{
sprite.body.velocity.copyFrom(game.physics.velocityFromAngle(sprite.angle, 300));
sprite.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(sprite.angle, 300));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var cursors;

function create() {

game.physics.startSystem(Phaser.Physics.ARCADE);

game.stage.backgroundColor = '#787878';

map = game.add.tilemap('mario');
Expand All @@ -40,7 +42,9 @@ function create() {

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

game.physics.gravity.y = 250;
game.physics.enable(p);

game.physics.arcade.gravity.y = 250;

p.body.bounce.y = 0.2;
p.body.linearDamping = 1;
Expand All @@ -54,7 +58,7 @@ function create() {

function update() {

game.physics.collide(p, layer);
game.physics.arcade.collide(p, layer);

p.body.velocity.x = 0;

Expand All @@ -79,7 +83,7 @@ function update() {

function render() {

game.debug.cameraInfo(game.camera, 420, 320);
game.debug.physicsBody(p.body);
// game.debug.body(p);
game.debug.bodyInfo(p, 32, 320);

}
53 changes: 0 additions & 53 deletions examples/tilemaps/mario.js

This file was deleted.

7 changes: 5 additions & 2 deletions examples/tilemaps/randomise tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var marker;

function create() {

game.physics.startSystem(Phaser.Physics.ARCADE);

map = game.add.tilemap('desert');

map.addTilesetImage('Desert', 'tiles');
Expand All @@ -33,11 +35,12 @@ function create() {
sprite = game.add.sprite(450, 80, 'car');
sprite.anchor.setTo(0.5, 0.5);

game.physics.enable(sprite);

game.camera.follow(sprite);

cursors = game.input.keyboard.createCursorKeys();


game.input.onDown.add(randomiseTiles, this);

}
Expand Down Expand Up @@ -68,7 +71,7 @@ function update() {

if (cursors.up.isDown)
{
sprite.body.velocity.copyFrom(game.physics.velocityFromAngle(sprite.angle, 300));
sprite.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(sprite.angle, 300));
}

}
Expand Down
6 changes: 5 additions & 1 deletion examples/tilemaps/replace tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var sprite;

function create() {

game.physics.startSystem(Phaser.Physics.ARCADE);

map = game.add.tilemap('desert');

map.addTilesetImage('Desert', 'tiles');
Expand All @@ -28,6 +30,8 @@ function create() {
sprite = game.add.sprite(450, 80, 'car');
sprite.anchor.setTo(0.5, 0.5);

game.physics.enable(sprite);

game.camera.follow(sprite);

cursors = game.input.keyboard.createCursorKeys();
Expand Down Expand Up @@ -64,7 +68,7 @@ function update() {

if (cursors.up.isDown)
{
sprite.body.velocity.copyFrom(game.physics.velocityFromAngle(sprite.angle, 300));
sprite.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(sprite.angle, 300));
}

}
Expand Down
7 changes: 5 additions & 2 deletions examples/tilemaps/shuffle tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var marker;

function create() {

game.physics.startSystem(Phaser.Physics.ARCADE);

map = game.add.tilemap('desert');

map.addTilesetImage('Desert', 'tiles');
Expand All @@ -33,11 +35,12 @@ function create() {
sprite = game.add.sprite(450, 80, 'car');
sprite.anchor.setTo(0.5, 0.5);

game.physics.enable(sprite);

game.camera.follow(sprite);

cursors = game.input.keyboard.createCursorKeys();


game.input.onDown.add(randomiseTiles, this);

}
Expand Down Expand Up @@ -68,7 +71,7 @@ function update() {

if (cursors.up.isDown)
{
sprite.body.velocity.copyFrom(game.physics.velocityFromAngle(sprite.angle, 300));
sprite.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(sprite.angle, 300));
}

}
Expand Down
27 changes: 11 additions & 16 deletions examples/tilemaps/tile callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,36 @@ var cursors;

function create() {

game.physics.startSystem(Phaser.Physics.ARCADE);

map = game.add.tilemap('map');

map.addTilesetImage('ground_1x1');
map.addTilesetImage('coin');

map.setCollisionBetween(1, 12);

map.setTileIndexCallback(26, hitCoin, this);

map.setTileLocationCallback(2, 0, 1, 1, hitCoin, this);

layer = map.createLayer('Tile Layer 1');

// layer.debug = true;

layer.resizeWorld();

game.physics.gravity.y = 100;
game.physics.arcade.gravity.y = 100;

sprite = game.add.sprite(260, 100, 'phaser');
sprite.anchor.setTo(0.5, 0.5);
sprite.anchor.set(0.5);

sprite.body.setRectangle(16, 16, 8, 8);
game.physics.enable(sprite);

sprite.body.setSize(16, 16, 8, 8);

// We'll set a lower max angular velocity here to keep it from going totally nuts
sprite.body.maxAngular = 500;

// Apply a drag otherwise the sprite will just spin and never slow down
sprite.body.angularDrag = 50;

// sprite.body.bounce.x = 0.8;
// sprite.body.bounce.y = 0.8;

debugSprite = sprite;

game.camera.follow(sprite);

cursors = game.input.keyboard.createCursorKeys();
Expand All @@ -72,7 +67,7 @@ function hitCoin(sprite, tile) {

function update() {

game.physics.collide(sprite, layer);
game.physics.arcade.collide(sprite, layer);

sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
Expand All @@ -89,14 +84,14 @@ function update() {

if (cursors.up.isDown)
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
game.physics.arcade.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}

}

function render() {

// game.debug.bodyInfo(sprite, 16, 24);
// game.debug.physicsBody(sprite.body);
game.debug.bodyInfo(sprite, 16, 24);
game.debug.body(sprite);

}
Loading

0 comments on commit f3ff9c1

Please sign in to comment.