【问题标题】:Phaser.js | Remove tilemap before change statePhaser.js |在更改状态之前删除 tilemap
【发布时间】:2017-07-02 15:19:36
【问题描述】:

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

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

Menu.js 加载前game.js

Menu.js 加载后game.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 的一部分

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(); 并返回 home 外观是正确的,我也认为是 map 使返回外观不好。

我试过了:

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

但总是相同的结果。

如果我使用:

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

是全部删除。

我看不出问题出在哪里。

【问题讨论】:

    标签: javascript jquery phaser-framework


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢。在我的情况下也很完美!
    【解决方案2】:

    我找到了解决方案。返回主菜单后需要重新定义世界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(){
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-21
      • 2023-01-28
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 1970-01-01
      • 2022-09-20
      相关资源
      最近更新 更多