phaser/examples/tilemaps/mario.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2013-10-22 02:58:20 +00:00
2013-11-01 12:25:14 +00:00
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
2013-10-22 02:58:20 +00:00
function preload() {
2013-11-01 12:25:14 +00:00
game.load.tilemap('mario', 'assets/maps/mario1.json', null, Phaser.Tilemap.TILED_JSON);
game.load.tileset('tiles', 'assets/maps/mario1.png',16,16);
game.load.image('player', 'assets/sprites/phaser-dude.png');
2013-10-22 02:58:20 +00:00
}
2013-11-01 12:25:14 +00:00
var map;
var tileset;
var layer;
var p;
var cursors;
2013-10-22 02:58:20 +00:00
function create() {
game.stage.backgroundColor = '#787878';
2013-11-01 12:25:14 +00:00
map = game.add.tilemap('mario');
tileset = game.add.tileset('tiles');
layer = game.add.tilemapLayer(0, 0, map.layers[0].width*tileset.tileWidth, 600, tileset, map, 0);
layer.fixedToCamera=false;
layer.resizeWorld();
cursors=game.input.keyboard.createCursorKeys();
2013-10-22 02:58:20 +00:00
}
function update() {
2013-11-01 12:25:14 +00:00
if (cursors.left.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.x -= 8;
}
2013-11-01 12:25:14 +00:00
else if (cursors.right.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.x += 8;
}
2013-11-01 12:25:14 +00:00
if (cursors.up.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.y -= 8;
}
2013-11-01 12:25:14 +00:00
else if (cursors.down.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.y += 8;
}
2013-11-01 12:25:14 +00:00
}