Jump to content

Phaser Offline. How to do it?


Salvatore
 Share

Recommended Posts

Hi!

How to use Phaser with full power on offline devices? My game is not an online only experience...

How to get working?

 

 

 

In a close future there will be a mobile app friendly version of Phaser? So we can distribute with PhoneGap, CocoonJS, etc...

 

 

Thank you!

Link to comment
Share on other sites

Nothing has to be online to use phaser. You have the full power of phaser in the javascript file phaser.js

If a mobile or tablet plays a game made with phaser then you would already have the phaser file in the source code so it would work no matter what. With or without internet connection.

If you wanted to test your phaser games offline without needing to use a host for you game then you have a few choices:

WAMP server - localhost

Node-Webkit

Both them options allow for offline testing but I'm sure that is said in the getting started guide for using phaser.

Hope this answers your question :)

Link to comment
Share on other sites

  • 2 weeks later...

I've tried to develop game in Phaser just by opening it in browser (without local http server) but I've got an error:

The cross-origin image at file:///C:(...) may not be loaded. p

 

To overcome this problem I've launched Chrome with flag "--allow-file-access-from-files" and for the time being it works like a charm.

For Firefox there is similar option in about:config.

 

My game is very, very simple so there is a chance that some new errors will appear in more complex projects but for me this is enough.

 

Please let me know if this work for you and if you have noticed any problem with this approach.

Link to comment
Share on other sites

  • 4 months later...

Hi all,

 

I found this link a while back. Not sure if the  writer already posted his solution in this forum, but  I'll link to his blog from this thread in case it may help someone in the future:

 

http://ksloan.net/how-to-run-phaser-html5-game-engine-without-a-web-server/

 

<quote>

Kevin Sloan / February 9, 2014
The Phaser engine forces you to load your app in a web server because it uses Cross-Origin-Resource-Sharing to load assets. This is a problem if you want to run your HTML5 game locally or wrap it up and run it in a native PhoneGap App.
 
The solution for me was to simply encode the sprites/audio I was using in base64 and include that in my js. I only had to change a few lines in the Phaser.Loader module:
 
file.data.src = file.url;
// file.data.crossOrigin = this.crossOrigin;
// file.data.src = this.baseURL + file.url;
Then instead of passing in the URL to the file, pass in the data itself like so:
 
game.load.spritesheet('birdie', 'data:image/png;base64,'+
'iVBORw0KGgoAAAANSUhEUgAAAGAAAAATCAYAAABvLghXAAABZElEQVR42u2YUQrCMAyGdwjB13kP'+
'z7GrCJ5qexC8mw8VnZOsa5K/TXAbthDEKV/+Jk3Wtmn0ERjzGpWvAU99tzCDs8qX4BRyvJ5nnxRM'+
'R4aTpNiU8L3xpxhZ+Kp4OokIHkqTm/q+B753fFihXKll9j1Y/B74NEZxokv4LKDrL1+TJqk4E1em'+
'NIkSPuIj/j2X753sZB+jwZcS8Hr+CEsjTsziET4NajukWe3HNqa/EVe+lAAOHjmBVnmO+BSfC/gi'+
'AcPm9M8rwJIApszU6or59L8oH1lArUE/ukDjdyjA9y8xrYdOAkpbHMK3tFBUP3oeUPhyGRe+ZCA+'+
'MoFSvpZgabeH6neKz+iE2zkgvQ/Y55omUcrPTLC7/uhwhh2xDdnN5mfup2E+x0o9t+h3js/Sibaf'+
'LrjrCLknyj/jzy+bnC+xVuML/d7MVw519Zp4x/xx3G+HQD8r/4f8Gpx1+W8wtcr35z8BKzsYemDt'+
'gtgAAAAASUVORK5CYII=', 24, 19)
 
You can use the same trick to load audio and other assets if you need too. Just read over that switch to see the ways Phaser loads each filetype, and replace it with the data. Obviously this is a quick fix, but it did everything I needed.
<end quote>
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...