我正在和 friend 一起制作游戏,我们在 AngularJS 和 Phaser 方面遇到了一些问题。
所以,我们有一个名为游戏的页面,它有一个模板、一个 Controller 和一个工厂。 有一个页面将我们“重定向”到游戏页面(仅带有链接)。
在模板中:
<div id="game"></div>
<a href="#/page">Back</a>
在工厂:
// function prealod and create ....
init: function(data) {
game = new Phaser.Game(width, height, Phaser.AUTO, 'game', { preload: preload, create: create });
},
destroy: function() {
game.destroy();
}
在 Controller 中:
gameFact.init();
$scope.$on('$destroy', function() {
gameFact.destroy();
});
当然,还有更多代码。
问题很简单:
如果我进入游戏页面,Phaser 会很好地加载游戏(我们只显示带有 Sprite 的 map )。 之后,我单击后退按钮并重新单击链接返回游戏页面。 如果我这样做 7 次,控制台中就会出现错误:
Uncaught SyntaxError: Failed to construct 'AudioContext': number of hardware contexts reached maximum (6).
几秒钟后,我遇到了这个错误:
Uncaught TypeError: Cannot read property 'gain' of undefined
我已经在网上搜索过,解决方案是:
- 使用 iFrame(我真的不认为 iFrame 是一个好的解决方案)
- 使用 destory 方法(不起作用)
你知道如何解决这个问题吗?
如果您有任何想法,请不要犹豫。即使您使用其他游戏框架(也许它的工作方式相同)。
最佳答案
我遇到了类似的问题,似乎 destroy()
无法正常工作 (issue discussed here)当前版本:
Could you please test out the dev branch, which has lots of fixes for this in.
我通过使用 dev 分支 (available here) 解决了该问题
关于javascript - 使用 AngularJS/Phaser.io 进行游戏并销毁方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26349588/