mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
53 lines
No EOL
1 KiB
JavaScript
53 lines
No EOL
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/tilemaps/maps/super_mario.json', null, Phaser.Tilemap.TILED_JSON);
|
|
game.load.image('tiles', 'assets/tilemaps/tiles/super_mario.png');
|
|
game.load.image('player', 'assets/sprites/phaser-dude.png');
|
|
|
|
}
|
|
|
|
var map;
|
|
var layer;
|
|
var p;
|
|
var cursors;
|
|
|
|
function create() {
|
|
|
|
game.stage.backgroundColor = '#787878';
|
|
|
|
map = game.add.tilemap('mario');
|
|
|
|
map.addTilesetImage('SuperMarioBros-World1-1', 'tiles');
|
|
|
|
layer = map.createLayer('World1');
|
|
|
|
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;
|
|
}
|
|
|
|
} |