playground icon indicating copy to clipboard operation
playground copied to clipboard

Destroy game instance?

Open ThePaavero opened this issue 9 years ago • 5 comments

I want to use this framework for a project where we'll be creating multiple games (within the same "page load") and will need to "destroy" instances on the fly. I can't seem to find a way to do that. Halp?

ThePaavero avatar Feb 05 '16 13:02 ThePaavero

Sure I can implement something like app.kill()

It would:

  • Remove all event listeners
  • Stop requestAnimationFrame
  • Remove the canvas (if you are using layer)

Then you would have to delete your app object from global scope like delete window.app so it can be garbage collected.

Sounds ok?

rezoner avatar Feb 05 '16 13:02 rezoner

On the other hand - if you don't want to wait for the update. Consider putting your games into IFRAMEs

rezoner avatar Feb 05 '16 13:02 rezoner

Yeah, your suggestion sounds great. Global scope is fine as we won't be running more than one game at any given time.

Thanks a ton, and keep me/us updated!

ThePaavero avatar Feb 05 '16 14:02 ThePaavero

@ThePaavero I have pushed new version. Sorry for the delay, I had many updates to merge.

app.kill() should remove all bound events and the canvas from DOM tree

rezoner avatar Feb 12 '16 13:02 rezoner

Thanks! I'll update the framework next week and report back if we run into any problems related to this. Thanks again!

ThePaavero avatar Feb 12 '16 13:02 ThePaavero