2017-03-28 113 views
0

我使用Phaser引擎創建了一個遊戲,並且我正在使用「平鋪」應用程序創建我自己的地圖。使用平鋪到Phaser遊戲中的多個圖層

實際的問題似乎是在創建此貼圖時有多個圖層。我有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; 
    } 
} 
} 

我現在用這種方式設置攝像頭,只是通過地圖飛行,以確保可以加載的東西。

道歉,如果這個問題的格式是退出,這是我第一次發佈!任何幫助將超級超值讚賞。

+0

你有沒有找到答案呢? – Reed

回答

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');