Loading assets as data URI's in Phaser 3

Posted on 22nd Aug 2018. Follow @phaser_ and get the Phaser World newsletter.


Quinten Clause writes "In this blogpost i'll explain how you can load the assets of your Phaser 3 game as data URI's, without having to rely on xhr requests. I'll cover images, spritesheets and audio.

Loading assets (like images and audio) in Phaser 3 is achieved by making xhr requests. This is fine if you are building a game for the web, but if your game isn't hosted on a server and needs to be loaded from the local filesystem, this will cause all kinds of troubles. Javascript is not allowed to make this kind of request when you are opening the html file with the file:// scheme.

We can solve this with data URI's. They are basicly complete images (or other files) that are represented by base64 encoded strings, which can be merged into your code rather then being loaded as external files."

Read More

The first book on the creation of HTML5 cross platform games using Phaser 3 and other free software.
  • By Emanuele Feronato
  • 155 Pages
  • 28 Source Code Examples
  • Build a complete game from start to finish
  • Cross Platform
  • Scaling for devices
Buy Now