2017-02-14 19 views
1

私はマルチゲームのプロジェクトを持っています。私はmenu.jsと多くのゲームjsページを持っています。Phaser.js |状態を変更する前にタイルマップを削除する

menu.jsロードページでは、表示が正しいです。 game.jsをロードしてmenu.jsに戻った後の画面は同じではありません。私は多くのソリューションを試しましたが、何も動いていません。私は最初と同じ様子を見せたいと思います。 menu.js

var menuState = { 
    create: function(){ 
     game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 
     game.scale.setGameSize(1000, 600); 
     game.scale.minWidth = 300; 
     game.scale.minHeight = 180; 
     game.scale.maxWidth = 1000; 
     game.scale.maxHeight = 600; 
     game.scale.pageAlignHorizontally = true; 
     game.scale.pageAlignVertically = true; 
     game.scale.updateLayout(true); 
     game.state.start("game"); 
    }, 
    start: function(){ 

    } 
} 

のパートgame.jsの一部を負担game.js enter image description here

game.js enter image description here

Menu.jsをロードする前に

Menu.js

this.map = game.add.tilemap('level2'); 
this.map.addTilesetImage('secondMap'); 
this.map.setCollisionByExclusion([13, 14, 15, 16, 46, 47, 48, 49, 50, 51]); 
this.map.setTileIndexCallback(225, this.test3, this); 
this.map.setTileIndexCallback(228, this.test, this); 
this.map.setTileIndexCallback(231, this.test2, this); 
this.layer = this.map.createLayer('Tile Layer 1'); 
this.layer.resizeWorld(); 

私は外観が正しいthis.layer.resizeWorld();を削除し、自宅に戻った場合、また、私はそれが悪いリターン登場mapだと思います。

私が試してみました:

this.layer.destroy(); 
this.map.destroy(); 
game.world.removeAll() 
game.state.clearCurrentState(); 

が、常に同じ結果を。

私が使用している場合:

game.state.destroy(); 
game.destroy(); 

がすべて削除されます。

どこが問題かわかりません。

答えて

1

は私も同様の問題を経験したが、私は(私の場合)私を務めGoogleで解決策を見つけたし、真剣に世界の限界を再定義します:

this.game.world.setBounds(0, 0, this.game.width, this.game.height); 
+0

ありがとうございます。私の場合も完璧です! –

0

解決策が見つかりました。ホームメニューに戻ると、世界widthheightを再編する必要があります。あなたがロードしたいすべてのゲームに世界widthheightを定義することも必要です。私の場合は

var menuState = { 
    create: function(){ 
     game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 
     game.scale.setGameSize(1000, 600); 
     game.scale.minWidth = 300; 
     game.scale.minHeight = 180; 
     game.scale.maxWidth = 1000; 
     game.scale.maxHeight = 600; 
     game.scale.pageAlignHorizontally = true; 
     game.scale.pageAlignVertically = true; 
     //------------------------ 
     game.world.width = 1000; 
     game.world.height = 600; 
     //------------------------ 
     game.scale.updateLayout(true); 
     game.state.start("game"); 
    }, 
    start: function(){ 

    } 
} 
関連する問題