简体   繁体   English

如何停止 Phaser 游戏并将其从页面中删除?

[英]How to stop a Phaser game and remove it from a page?

I have a single webpage that I want to be able to run three JavaScript games, sequentially.我有一个网页,我希望能够按顺序运行三个 JavaScript 游戏。 I start one with我开始一个

//jQuery to start a game
$(document).ready(() => {
  //When the logo image is clicked
  $("#logo").click(() => {
    //Get the archery game
    $.getScript('archery.js', () => {
      //Start it
      startArchGame();
      //Remove the image from the HTML doc
      $("#logo").remove();
    });
  })
})

Then, inside archery.js , once a condition is met, the following code is executed然后,在archery.js ,一旦满足条件,就会执行以下代码

$.getScript('skateboarding.js', () => {
  startSkateGame();
});
game.destroy();

The game.destroy(); game.destroy(); stops the game from running in Phaser 3, but the next game is just loaded below the first one, so you can't see it.停止游戏在 Phaser 3 中运行,但下一个游戏只是在第一个下方加载,所以你看不到它。 How can I fix this?我怎样才能解决这个问题? Is it possible to delete the first script I got entirely?是否可以完全删除我得到的第一个脚本?

I was able to solve this issue within the Phaser framework.我能够在 Phaser 框架内解决这个问题。

I changed game.destroy() to game.destroy(true, false) .我将game.destroy()更改为game.destroy(true, false) The first argument of the destroy method, true , says that I want to remove the game from the canvas element of the page when I destroy the game. destroy 方法的第一个参数true表示我想在销毁游戏时从页面的画布元素中删除游戏。 The second argument, false , says to NOT remove all of Phaser and its plugins for the page.第二个参数false表示不要删除页面的所有 Phaser 及其插件。 I set this to false because I want to create another game in Phaser on the page after I destroy my first one.我将此设置为 false 是因为我想在销毁第一个游戏后在页面上的 Phaser 中创建另一个游戏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM