var game = new Phaser.Game(config);
var controls;
function preload(){
this.load.image('tiles', 'assets/dungeonSet.png'); //tileset
this.load.tilemapTiledJSON('map', 'assets/dungeonLevel1.json'); //tilemap
}
function create(){
var map = this.make.tilemap({ key: 'map' });
var tiles = map.addTilesetImage('dungeonSet', 'tiles');
var layer = map.createStaticLayer(0, tiles, 0, 0).setDepth(0); //
// add the platform layer
var platformLayer = map.createDynamicLayer('nameOfLayerInTiled', tiles, 0, 0).setDepth(1);
// declare the collisions
platformLayer.setCollisionByProperty({ collides: true });
// add a collider between a sprite and the platformLayer
this.physics.add.collider(player, platformLayer, undefined, undefined, this);
this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
var cursors = this.input.keyboard.createCursorKeys();
var controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
speed: 0.5
};
controls = new Phaser.Cameras.Controls.FixedKeyControl(controlConfig);
}
function update (time, delta)
{
controls.update(delta);
}
1 Like