Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Game Restart slows down Game dramatically


valueerror
 Share

Recommended Posts

as you can see here in my demo game

 

http://test.xapient.net/phaser/tilemap/

 

if you die (touch a block with spikes or just fall of the screen)  you will respawn.. actually it will just restart the current game state  -  this is just a simple line of code:

game.state.start('start', true, true);

true,true should clear all the cache.. right? (i thought this should provide a clean and fresh restart)  

i also remove global timer events to be sure nothing runs anymore.. but still..  

 

i didn't see it when testing the game on my desktop (although if you try it on a 4 year old machine and you die a few times you will see it nevertheless - because it gets slower every time)

if you test it on a tablet you'll see it after the first respawn.. it is unplayable slow..

 

please help!  what did i miss ? something seems to be still running or initialized more than once..  

 

thank you!

Link to comment
Share on other sites

so var total shows 480 on every restart of the state..   with the newest version i had to set "clear cash" to false (otherwise it wouldn't start the gamestate because of missing elements..   but nevertheless..  it works now! even on my nexus7 there is no noticeable drop in performance anymore..

thx rich!! however you did it :) 

Link to comment
Share on other sites

I have noticed also that since I upgraded to 1.2, every game state change decreases performance.

 

I have a Menu state and a Game state. The first time I press the "PLAY" button in the Menu state, it takes up to 1-2 seconds preloading all the animations before game starts. 

If I come back to the Menu state and press "PLAY" again, it will take longer and longer before the Game state is playable.



NOTE: I'm not using any physics at all.

Link to comment
Share on other sites

I'm not noticing any speed decrease on a state change. Could you grab the latest source (not the build file, but the actual source) and try it and see if it still happens? If so please do a chrome dev tools profile on it, see what is going on / taking up the time.

Link to comment
Share on other sites

Downloaded the latest source and built it. Still having the same issue.

 

I started the game, switched around 15 times between Menu and Game state. Then profiled CPU usage when clicking PLAY.

 

After that, I reloaded the the webpage and profiled the CPU usage the first time I clicked "PLAY" and changed state to Game.

This is the result of the first profile:

 

P4e2ztK.png

And this is the second one, first time I change states:

 

OEMa8Te.png

 

 

Animal and Arbusto are just extended Sprite objects that are created as soon as the game starts.

 

You can download the full CPU profiles here:

 

https://dl.dropboxusercontent.com/u/18980037/CPUProfiles/CPU-20140312T231612.cpuprofile

https://dl.dropboxusercontent.com/u/18980037/CPUProfiles/CPU-20140312T232824.cpuprofile

Link to comment
Share on other sites

Are you 100% sure 'destroy' is being called on your custom objects? If not it's just going to carry on persisting in the world. Same for your states actually.

 

Try counting how many children are on the display list when the game restarts. Can just do game.world.children.length

Link to comment
Share on other sites

Every custom object I have extends Sprite. As far as I know, all of them should be automatically destroyed on game state change, please correct me if I'm wrong.

 

I made a couple of console.log over the world children length as you suggested. The first one is on entering the game state, the second one is when you press the back to menu button in the game state.

 

Everything seems to be OK:

 

WQALf7c.png

Link to comment
Share on other sites

We created a complete multi-state test today, generating hundreds of sprites (with and without physics bodies) and we're not seeing any slow down when swapping. The display list clears properly and the physics world is reset. So going to need a specific test case (source code + assets I can run here) to get any further I'm afraid.

Link to comment
Share on other sites

  • 1 year later...

I've been trying to solve this problem for a while now and it is driving me mad. Have you had any luck?  I'm using version 2.3.0. 

 

For me the problem is a bit different ... not only does calling game.state.start on the current game state crash the game, but when you try to load the game in a different browser session, it crashes as well... let me try and explain that better. 

 

1. Game works just fine, everything is hunky-dory and I have no performance issues whatsoever .

2. Add a button to the game which calls game.state.start(current.game.state); Click the button.

3. Everything crashes. 

3. Try loading up the game after restarting the browser, clearing cache, etc, but the game still isn't working. It doesn't make any sense because technically the game is in the same state it was in #1 .. I'm not clicking the button and restarting the current state... I'm just booting the game as normal.  

 

I just don't understand. This issue has plagued me for months. Sometimes a computer restart will cause the game to start working again. But what the hell does a computer restart have to do with anything? What could possibly be based by Phaser from one sessions to another session other than cache?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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