valueerror Posted March 9, 2014 Share Posted March 9, 2014 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 More sharing options...
rich Posted March 9, 2014 Share Posted March 9, 2014 Check to see if the physics world is actually being cleared or not (you can ask it how many bodies exist when it starts to find out). My guess is it's starting simulation after simulation. Link to comment Share on other sites More sharing options...
valueerror Posted March 10, 2014 Author Share Posted March 10, 2014 sorry to bother you.. but how do i ask how many bodies exist? countDead() or countLiving() allways gives me "0" or "4" - i couldn't find out how to count ALL physics bodies.. thank you! Link to comment Share on other sites More sharing options...
rich Posted March 10, 2014 Share Posted March 10, 2014 Update to the latest build and you can do:var total = game.physics.p2.total; Link to comment Share on other sites More sharing options...
valueerror Posted March 12, 2014 Author Share Posted March 12, 2014 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 More sharing options...
mariogarranz Posted March 12, 2014 Share Posted March 12, 2014 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 More sharing options...
rich Posted March 12, 2014 Share Posted March 12, 2014 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 More sharing options...
mariogarranz Posted March 12, 2014 Share Posted March 12, 2014 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: And this is the second one, first time I change states: 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.cpuprofilehttps://dl.dropboxusercontent.com/u/18980037/CPUProfiles/CPU-20140312T232824.cpuprofile Link to comment Share on other sites More sharing options...
rich Posted March 13, 2014 Share Posted March 13, 2014 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 More sharing options...
mariogarranz Posted March 13, 2014 Share Posted March 13, 2014 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: Link to comment Share on other sites More sharing options...
rich Posted March 13, 2014 Share Posted March 13, 2014 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 More sharing options...
mariogarranz Posted March 13, 2014 Share Posted March 13, 2014 Well my code is quite messy right now. I will try to clean it up and send you the whole game in case you want to try it yourself. Thank you very much. Link to comment Share on other sites More sharing options...
ForgeableSum Posted June 21, 2015 Share Posted June 21, 2015 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 More sharing options...
Recommended Posts