dr.au Posted July 27, 2016 Share Posted July 27, 2016 Play the game and use Chrome inspector to emulate iPhone 5 View source on GitHub The game feels glitchy, dragging and not smooth on an iPhone 6: Nothing stands out as being the culprit alone when profiling in Chrome. Profiling each game component in isolation runs well: the player, input, platforms, coins, enemies, music, background graphics all run well, but the combination together seems to trigger more Garbage Collection (GC) and long frames. All assets are 2x Retina Platforms, coins and enemies are all object pooled Update() loops have var instances removed as much as possible to reduce GC Player has fixed X position and moving elements have body.velocity.x = -280 to avoid large X values and avoiding the game.camera object How can I optimize for better mobile performance regarding garbage collection and long frame issues? Link to comment Share on other sites More sharing options...
drhayes Posted July 28, 2016 Share Posted July 28, 2016 Caveat: I have no experience writing Phaser games for mobile, like none. When you profile, try to profile on the platform you're testing. Things that are just fine on desktop (non-power-of-two textures, otherwise large memory usage) can play hell with mobile. The Chrome browser will only emulate the viewport size, not the platform itself. Remote debugging via an iOS device would be preferable; the iPhone simulator via XCode probably won't show the same behavior either. Those setText calls in Game.update probably aren't doing you any favors. Maybe try setting those only when the values change. Your leafy sprite overrides kill but doesn't call Phaser.Sprite's kill. I don't think that would cause perf issues, but it's a thing I noticed. dr.au 1 Link to comment Share on other sites More sharing options...
dr.au Posted July 29, 2016 Author Share Posted July 29, 2016 drhayes — turns out those setText calls were extremely expensive! Refactoring them dropped my CPU use 50%! Even this was much more performant and still gives the impression of a constantly increasing score: game.time.events.loop(60, updateScore, this); function updateScore() { game.scoreText.setText(vars.score); } Also looking into cleaning up the kill() function. Thanks for your help! Link to comment Share on other sites More sharing options...
Recommended Posts