javascript - Phaser.js |在更改状态之前删除图 block map

标签 javascript jquery phaser-framework

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

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

加载 game.js 之前的

Menu.js enter image description here

加载game.js后的

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

删除全部。

我不明白问题出在哪里。

最佳答案

我也遇到了类似的问题,但是我在 Google 中找到了解决方案这对我很有帮助(就我而言),并将认真地重新定义世界的界限:

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

关于javascript - Phaser.js |在更改状态之前删除图 block map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42224386/

相关文章:

javascript - 从 v3 升级到 v5 时代码不起作用

javascript - Chrome : window. 打印与 ctrl + p

javascript - jquery - 获取其他页面的内容

javascript - HighStocks 可拖动元素干扰 gridster 拖动

javascript - 用户选择选项后如何从选择标签获取数据att

javascript - 将动画 Sprite 添加到移相器对象

javascript - 如何将处理程序 ID 添加到 jQuery 加载的选项值

jquery - 委托(delegate)是最快的绑定(bind)方式吗?

javascript - 为了获得 `tweens` 动画的目标 x 和 y,我使用了 SOHCAHTOA,我只是想知道 Phaser 3 是否提供了一个方便的工具来完成这项工作

javascript - 开 Jest 导入语句 : 'TypeError: Cannot set property ' fillStyle' of null'