Phaser.js |在更改状态之前删除tilemap

时间:2017-02-14 10:58:22

标签: javascript jquery phaser-framework

我有一个多游戏项目。我有一个menu.js和很多游戏js页面。

menu.js加载页面中,视图正确无误。加载game.js并在menu.js中返回后,屏幕就不一样了。我尝试了很多解决方案,但没有任何工作。我想在开始时表现出相同的外观。

加载Menu.js之前

game.js enter image description here

加载Menu.js

game.js enter image description here

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的一部分

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

删除全部。

我不知道问题出在哪里。

2 个答案:

答案 0 :(得分:1)

我也遇到了类似的问题,但是我在Google找到了一个解决方案(在我的情况下),并且会严重重新定义世界的极限:

localtime_s

答案 1 :(得分: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(){

    }
}
相关问题