Skip to content

Instantly share code, notes, and snippets.

@MarcL
Created March 10, 2017 09:19
Show Gist options
  • Save MarcL/748f29faecc6e3aa679a385bffbdf6fe to your computer and use it in GitHub Desktop.
Save MarcL/748f29faecc6e3aa679a385bffbdf6fe to your computer and use it in GitHub Desktop.
Tips on speeding up Phaser games

From here: http://www.html5gamedevs.com/topic/9931-mobile-performance-tips-tricks/

P2:

  • polygon shapes will be more expensive than simple circles - especially huge polygons (keep them simple)
  • enabling p2 impactEvents is expensive - use onBeginContact instead
  • having a bunchload of revolute constraints seems to be expensive

Arcade:

  • don't call  game.physics.arcade.collide   20 times in the update loop.. try to do the same thing with 5 calls ;-)

Both (general programming) :

  • reuse sprites whenever possible - create multiple / kill and revive them (e.g. bullets)
  • be careful with the resolution of your game 640x480 will run faster than 1024x768
  • keep physics simple 
  • instead of "game.time.now" use "game.time.time" or one of the physicsElapsed values, as "now" can often contain high precision timer values (depending on the browser)
  • arcade is faster than p2
  • rendering normal text is expensive, using bitmap-fonts seems to be better but is still somehow heavy on mobile 
  • using tilemaps with more than 2 layers is going to be slow (depending on your device) - try the new tilemap plugin
  • huge tilemaps will be slow
  • when using webGL use a sprite atlas that contains all your sprites instead of many different image files.
  • make use of the particles system - but not to much ^^ (it may be better to use the particlesystem than to create all particles "by hand" but spawning particles will cause a frame drop on slow devices)
  • try to keep the update loop simple - do not call a function 60 times a second if not definitely needed
  • make sure the garbage collector can free some memory - use var  ^^
  • make sure the garbage collector doesn't have too much to do - don't create new objects all the time (functions are treated in the same way)  and finding the balance between to much and to little is the trick
  • don't use the native webview (especially on older android versions) - use a wrapper (like cocoonjs) or use intel crosswalk (which builds on chromium)
  • intel  crosswalk seems to run much better with webgl enabled
  • cocoonjs seems to run much better in canvas mode
  • do not use splice. If you have only one element to cut off an array, use this function, which is multiple times faster that the build in one, and aside it low GC (the built in is the opposite!): 1-item-splice
  • using a lot of tweens in parallel can cause lags
  • using Prototype simply slows down things. It's faster to use precached functions
  • do not use classes, no new, no prototype, no this, track length by yourself, use custom splice or avoid it completely by using double linked lists
  • tweens that start on creation of a state will be choppy.. use game.time.events.add(1, fadeIn); to delay the tween (it seems that game.time.events will not start before everything is loaded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment