mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
59 lines
No EOL
1.1 KiB
JavaScript
59 lines
No EOL
1.1 KiB
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
|
|
|
function preload() {
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
var map;
|
|
var tileset;
|
|
var layer;
|
|
var p;
|
|
var cursors;
|
|
|
|
function create() {
|
|
|
|
game.stage.backgroundColor = '#787878';
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
function update() {
|
|
|
|
if (cursors.left.isDown)
|
|
{
|
|
game.camera.x -= 8;
|
|
}
|
|
else if (cursors.right.isDown)
|
|
{
|
|
game.camera.x += 8;
|
|
}
|
|
|
|
if (cursors.up.isDown)
|
|
{
|
|
game.camera.y -= 8;
|
|
}
|
|
else if (cursors.down.isDown)
|
|
{
|
|
game.camera.y += 8;
|
|
}
|
|
|
|
} |