rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

Destroy game instance? #31

Open ThePaavero opened 8 years ago

ThePaavero commented 8 years ago

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?

rezoner commented 8 years ago

Sure I can implement something like app.kill()

It would:

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 commented 8 years ago

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

ThePaavero commented 8 years ago

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!

rezoner commented 8 years ago

@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

ThePaavero commented 8 years ago

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