Jump to content

Destroy Phaser Game Completely


MarvinB
 Share

Recommended Posts

Hi Guys,

this is my first post here and I hope that I have been putting it under the right category  :wacko:

 

So I am working with AngularJs to add some menus before my game starts. I am also using EZGUI to add some ingame menus.

I really need the Angular part that I have already built cause I am doing more complex things like user authentication in there, which I don't wanna do in Phaser.

 

To my problem:

I am trying to switch views between my Angular part and the Phaser Game. I got something working that actually lets me change in and out of my game without any lags, but gives me the following error, when I loaded the game once, switched back into my Angular part and then switch back into my game:

 

Uncaught TypeError: Cannot read property 'cache' of null

 

Important to mention here is probably how I go about switching my views. In my game controller that loads my game into my div (canvas), I wrote a little function that lets me load scripts asynchronously and appends them to the head, when I switch out of my game into my Angular menu controller. I remove that script again from the DOM to be able to reload it later again. The script is fairly tiny so it doesn't take up much loading time.

It only contains my game setup:

 

 

(function() {
    var game = new Phaser.Game(screen.width, screen.height, Phaser.CANVAS, 'gameCanvas');
 
    // add our game states
    game.state.add('boot', MMM.Boot);
    game.state.add('preload', MMM.Preload);
    game.state.add('main-game', MMM.MainGame);
 
    // start with the booting state
    game.state.start('boot');
})(); 

 

 

I am also clearing the cache with this.game.cache.destroy(); and I am destroying the game with this.game.destroy(); in my main game file before I switch into the Angular menu controller again. I am basically trying to remove the game components completely right before I switch into my menu controller, because the user might reside there for a while (chatting, looking through the store, setting up a new password, etc...) and I don't want any game related components running in the back during that time.

 

I have been searching through quite some forum articles trying to find what I am looking for. I read somewhere that Phaser attaches additional eventHandlers to the window object, which aren't removed when you call this.game.destroy() 

 

I hope somebody out there tried something similar and can help me out on this one. I am quite stuck here :S

Any help is appreciated!  :)

 

 

 

Link to comment
Share on other sites

Hey Marvin,

I've got an Angular app that has a Phaser game as an Angular view. I haven't had any problems so far, but not sure if what I'm doing is a complex. I basically have different 'pages' some of them are all Angular, some nest a canvas running Phaser. If you stay stuck let me know and I'll send you a skeleton of my project. 

Good luck.

Link to comment
Share on other sites

  • 7 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...