Stephan Posted July 30, 2018 Share Posted July 30, 2018 Hi all, Currently I am trying to add a bunch of Panda2 games in my Vue.js SPA where I intend to embed a complete panda.js game in an isolated component. In order to keep the code as clean as possible, I would like to create a new game instance when the component is mounted en destroy it completely then the component is destroyed itself. I managed to destroy the canvas and delete the game instance located at window.game. However, it appears that the engine is still running because I am getting a cascade of the following error: system.js:336 Uncaught ReferenceError: game is not defined at Class._run (system.js:336) at eval (core.js?b5d7:855) at animate (core.js?b5d7:951) ...which means that the engine is still running somehow. My question: Is there a way to terminate the panda game process? Stephan Quote Link to comment Share on other sites More sharing options...
enpu Posted July 30, 2018 Share Posted July 30, 2018 Looks like the game loop is still running. There is private function _stopRunLoop in System class, which should do the trick: game.system._stopRunLoop(); Quote Link to comment Share on other sites More sharing options...
Stephan Posted July 30, 2018 Author Share Posted July 30, 2018 thanx for your quick reply! ? Your suggestion works all right and the engineloop is terminated. I still get the following error: VM10871 input.js:200 Uncaught ReferenceError: game is not defined at Class._mouseup (VM10871 input.js:200) at eval (core.js?b5d7:855) Which seems logical, since there are several eventlisteners attached to the window during startup in input.init(). unfortunately I cannot remove these eventlisteners since they have been attached with bind(). As a result I don't have a copy of the exact same instance that was bound to window and removeEventlistener() cannot be used. ? I could make a few adjustments to the engine to make things work but I am a bit reluctant to do all that and ending up with a separate branch... Another approach would be to keep the instance of window.game available. @enpu: What are your thoughts on this? Is it possible to restart the engine with a new canvas and WEB_GL settings? Quote Link to comment Share on other sites More sharing options...
enpu Posted July 30, 2018 Share Posted July 30, 2018 Hmm maybe i should create new function, like game.stop() that would handle all that is necessary to completely stop the engine? Quote Link to comment Share on other sites More sharing options...
Stephan Posted July 30, 2018 Author Share Posted July 30, 2018 That would be GREAT! ? Do you need any help from me on this? Quote Link to comment Share on other sites More sharing options...
enpu Posted July 31, 2018 Share Posted July 31, 2018 I just added new game.stop() function to dev branch. It will stop the engine completely and remove all event listeners. It also has one parameter, which if you set to true, will also remove the canvas. game.stop(); // Stop engine completely and remove all event listeners game.stop(true); / Stop engine and also remove canvas Let me know how it works Quote Link to comment Share on other sites More sharing options...
Stephan Posted July 31, 2018 Author Share Posted July 31, 2018 nice work! Thank you for implementing this feature so quickly! I will give it a try tonight and let you know if all works well. Quote Link to comment Share on other sites More sharing options...
Stephan Posted July 31, 2018 Author Share Posted July 31, 2018 Yep, it works like a charm! Now I can intergrate all pandagames in any Vue project and load them dynamically without problems. Thanx again for this great update.? Quote Link to comment Share on other sites More sharing options...
enpu Posted July 31, 2018 Share Posted July 31, 2018 No problem! Good to hear that it worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.