javascript - How to stop a Phaser game and remove it from a page? - Stack Overflow

I have a single webpage that I want to be able to run three JavaScript games, sequentially. I start one

I have a single webpage that I want to be able to run three JavaScript games, sequentially. 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

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

The 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. How can I fix this? Is it possible to delete the first script I got entirely?

I have a single webpage that I want to be able to run three JavaScript games, sequentially. 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

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

The 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. How can I fix this? Is it possible to delete the first script I got entirely?

Share Improve this question edited Jan 6, 2020 at 18:50 Robert Smith asked Dec 23, 2019 at 0:02 Robert SmithRobert Smith 73312 silver badges29 bronze badges 7
  • is there an example that you demonstrate the issue? – Nidhin Joseph Commented Dec 23, 2019 at 0:08
  • @NidhinJoseph would a GitHub repo work for you? – Robert Smith Commented Dec 23, 2019 at 0:09
  • yes, share the link please – Nidhin Joseph Commented Dec 23, 2019 at 0:11
  • @NidhinJoseph github./roberto257/Olympic-Games – Robert Smith Commented Dec 23, 2019 at 0:14
  • @RobertSmith have you found an answer to this issue? – Manuel Abascal Commented Dec 31, 2019 at 1:41
 |  Show 2 more ments

1 Answer 1

Reset to default 8

I was able to solve this issue within the Phaser framework.

I changed game.destroy() to 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. The second argument, false, says to NOT remove all of Phaser and its plugins for the page. I set this to false because I want to create another game in Phaser on the page after I destroy my first one.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744810530a4595031.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信