使用从Tiled进入Phaser游戏的多个层

时间:2017-03-28 03:24:53

标签: javascript phaser-framework tiled

我正在使用Phaser引擎创建游戏,而我目前正在使用该应用程序' Tiled'创建我自己的tilemap。

实际问题似乎是在创建此tilemap时有多个图层。我有6个不同的层:

  • "背景"
  • " WallBlocks"
  • "草"
  • " SpikeAnimation"
  • " DiamondAnimation"
  • " SlimeAnimation"

这是我的Game.js文件

SleepSim.Game = function (game) {
this.map;
this.Background;
this.WallBlocks;
this.Grass;
this.SpikeAnimation;
this.DiamondAnimation;
this.SlimeAnimation;
}
SleepSim.Game.prototype = {
create: function () {
    this.world.setBounds(0,0,5000,1000);

    this.map = this.add.tilemap('gameWorld');

    this.map.addTilesetImage('gameworld', 'tiles');

    this.Background = this.map.createLayer('Background');
    this.Background.resizeWorld();

    this.WallBlocks = this.map.createLayer('WallBlocks');
    this.Grass = this.map.createLayer('Grass');
    this.SpikeAnimation = this.map.createLayer('SpikeAnimation');
    this.DiamondAnimation = this.map.createLayer('DiamondAnimation');
    this.SlimeAnimation = this.map.createLayer('SlimeAnimation');
},
update: function() {
    if(this.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
        this.camera.y += 10;
    }
    else if (this.input.keyboard.isDown(Phaser.Keyboard.UP)){
        this.camera.y -= 10;
    }
    if (this.input.keyboard.isDown(Phaser.Keyboard.LEFT)){
        this.camera.x -= 10;
    }
    else if (this.input.keyboard.isDown(Phaser.Keyboard.RIGHT)){
        this.camera.x += 10;
    }
}
}

我现在以这种方式设置相机,只是飞过地图以确保可以加载。

如果此问题的格式化已经过时,请致歉,这是我第一次发帖!任何帮助都将超级赞赏。

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题。您只需要为第一层创建一个变量,其余的不应该是变量。

this.map = this.add.tilemap('gameWorld');

this.map.addTilesetImage('gameworld', 'tiles');

this.Background = this.map.createLayer('Background');
this.Background.resizeWorld();

this.map.createLayer('WallBlocks');
this.map.createLayer('Grass');
this.map.createLayer('SpikeAnimation');
this.map.createLayer('DiamondAnimation');
this.map.createLayer('SlimeAnimation');