G3n3ralTao Posted January 29, 2016 Share Posted January 29, 2016 Hello, We are currently developping an iOS application using Cordova and we are facing a strange issue. If the application return from background mode, the game slow down drasticly. We are talking about 5-10 fps instead of 30. We added a callback function on the document event "resume" to reload the application using the location.reload() function, but this solution work 4 time out of 5. Either it working well at 30 fps or we are back at the 5-10 fps. Preventing the application to enter background mode isn't an option since the issue happen when the device is closed manually. It seem that this action doesn't count has a background mode and the framerate goes into "abysmal mode" yet again. We looked into Cordova bug tracker to see if a similar issue was experienced by other user, but so far we found nothing. So we were wondering if anyone had similar issues or any explication on why this is happening. Thank you in advance Link to comment Share on other sites More sharing options...
danielbeck Posted January 31, 2016 Share Posted January 31, 2016 I have the same issue: After switching between apps, the game gets really slow when reactivated. It drops from 60fps to 6fps and remains slow until the game is stopped and restarted. The game is packaged with phonegap/cordova and uses canvas-mode for rendering. This behaviour only occurs on iOS (here iOS 9). Link to comment Share on other sites More sharing options...
rcoaxil Posted January 31, 2016 Share Posted January 31, 2016 Most likely a bug in Cordova's underlying framework. Try to trace exactly what causes the slowdown. Run a profiler to see which functions' running time skyrockets after switching. I never worked with those, but I have a hunch this has to do with framework pumping huge amount of events trying to catch up for the time it wasn't running. Link to comment Share on other sites More sharing options...
G3n3ralTao Posted February 1, 2016 Author Share Posted February 1, 2016 Thank you for the input. I will investigate that. In the meantime, I did some tests including pausing Phaser while the application is in background mode, but even then the performance doesn't improve unfortunately. In Xcode, I also get weird thread warnings: "THREAD WARNING: ['NetworkStatus'] took '17.43452' ms. Plugin should use a background thread." But I get that at start-up, but the application doesn't slow down. I dug around on that topic and every one is saying that this warning is harmless. Might be related in a weird and twisted way (Like most things with Cordova) since it's not always the same plugin that is mentioned in the Xcode console. I'll keep updating this thread has I find new clues or solution to this problem. Link to comment Share on other sites More sharing options...
G3n3ralTao Posted February 4, 2016 Author Share Posted February 4, 2016 Ok, small update. Still investigating. With the Safari developer console's profiler and I found that when our application return from the background mode the update RAF call in the "loop" function take at least 0.020ms more time on each frames. I tried forcing Phaser to use of setTimeout over requestAnimationFrame, but I still get the same delay on each calls. I am experimenting with the Phaser configuration to try and find an option that might cause this delay in the game loop but so far, no luck. I found no way to look into Cordova inner working to find if the delay would come from it, but then again, it's Phaser that get the delay during it loop call. I am still digging, I'll keep you posted on my findings. Link to comment Share on other sites More sharing options...
G3n3ralTao Posted February 4, 2016 Author Share Posted February 4, 2016 Got it! For some reason, the RAF isn't stopped while the application is in background mode. To fix this, you need to add the following event listeners: document.addEventListener("pause", function() { game.paused = true; game.raf.stop(); }, false); document.addEventListener("resume", function() { game.paused = false; game.raf.start(); }, false); I force the engine to pause just to be sure. I didin't receive any paused/resumed events during my tests and Time would continue to run in background mode. I just found out that solution and I only test it on 3 devices. I am about to send it to the QA departement, so if we find any other issue with the background mode, I'll update this topic. Bonne fin de journée! dr.au 1 Link to comment Share on other sites More sharing options...
dr.au Posted February 5, 2016 Share Posted February 5, 2016 I also have this problem, will try this excellent fix! Does anyone have audio problems on first load of their app? My MP3 audio playback in phaser sounds modulated until I force refresh the page and all is well. Link to comment Share on other sites More sharing options...
dr.au Posted February 5, 2016 Share Posted February 5, 2016 16 hours ago, G3n3ralTao said: document.addEventListener("pause", function() { game.paused = true; game.raf.stop(); }, false); document.addEventListener("resume", function() { game.paused = false; game.raf.start(); }, false); Confirmed, this also fixed my phonegap resume issue. Thanks so much @G3n3ralTao! Link to comment Share on other sites More sharing options...
G3n3ralTao Posted February 5, 2016 Author Share Posted February 5, 2016 No problem! @rich You might want to take a look at this issue Link to comment Share on other sites More sharing options...
Recommended Posts