Jump to content

Phaser on NodeJS


tips4design
 Share

Recommended Posts

I am trying to run Phaser on a Node server, I did it as described here: http://www.html5gamedevs.com/topic/7393-running-phaser-on-nodejs-how-i-did-it-and-why-you-shouldnt-do-it/

Everything seems ok (the script starts Phaser, enters the boot state). The problem is that it makes an XHR request and throws error at this._xhr.open. This may be because I load resources (sprite images). How can I overcome this problem? I have tried installing a Node XHR, but says the protocol is not valid (the protocol used by Phaser when loading an image I guess). How can I correctly load sprites? Or, how can I stop sprites from loading (be able to use them, but as empty images, anyway I don't render them on the server).

 

Spent a few hours on this and still no results, any help would be greatly appreciated.

Link to comment
Share on other sites

Using this XHR instead of the default XHR module seemed to have fix the problem: https://www.npmjs.com/package/local-xmlhttprequest

 

Some other tips for running a Phaser game on NodejS using the exact same code as on the client:

 

  • Most of the steps here still apply: http://www.html5game...shouldnt-do-it/ . Encountered problems while installing node canvas, fixed them by isntalling Node.js 32bit instead of 64bit.
  • Use requireJS client and server side, because on node there is no index.html file in which you can include script tags
  • Define each of your game files as requireJS modules, make sure to use a define gist to work with requireJS on the server
  • I needed to use the above library, local-xhtmlhttprequest in order to be able to load images on the server. I encountered some problems with the paths (first XHR request was fine, second was requesting from the node_modules folder instead of the correct path). Hack fixed it by using the absolute path.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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