Jump to content

Using Phaser with node/socket


Chaosus
 Share

Recommended Posts

Hi, I am currently trying to do a multiplayer game (actually now I just try to move a sprite in a window and make it visible from another window), and I don't know how to include the phaser.min.js file. I red that I have to do it like : var phaser = require('./phaser.min.js') in the server file, but this doesn't work. It's the same if I do like

<script type="text/javascript" src="/phaser.min.js"></script>

or

<script type="text/javascript" src="http://localhost/phaser.min.js"></script>

 

I still have the console log : Phaser is not defined

 

I know that's a pretty small issue but I have not a clue about how to include this. Thanks !

Link to comment
Share on other sites

I plan on using phaser with node.js too.

Really wanna do some online multiplayer, I have only started to research it a little.

 

My question for you is: why do you need phaser on the server side?

 

I mean, from what I am thinking right now my scenario would look like this:

 

browser a - running a phaser game, sending x,y positions to the server via websocket

server -running a nodejs that takes x,y values from clients and sends them to all clients

browser b - running the same phaser game, receiving x,y positions from the server, positioning the sprites correctly

 

That would not require phaser to run on the server.

(except if the server has to do the physics and you want to use those of phaser.. haven't looked into that so far.)

Link to comment
Share on other sites

The way I want to do it is exactly as you described it, so I don't care about using Phaser on the server side, but for an unknown reason I can't use it either on the client side, even if I included it like every of my other projects.

 

I thought that the inclusion of file wouldn't work the "normal way" because of a small dumb mistake : i wrote

<script type="text/javascript" src="/phaser.min.js"></script>

instead of

<script type="text/javascript" src="./phaser.min.js"></script>

Any way so this is solve now.

 

Basically I think it will be easy to do an online multiplayer game with node and Phaser, but I saw that it's impossible to have a different camera for the different players for the moment.

Link to comment
Share on other sites

No... I'm not dreaming, it still doesn't work. Il successes to include when I lunch index.html with the brower, but it fails if I lunch it by connection to localhost:8080.

I think that there is something to do to just include the file in the index.html.

Link to comment
Share on other sites

I don't know if Phaser could work outside a browser for now (there was an old post on this topic) because it is DOM based : it needs tu use/create a html canvas element and it repaints the browser display each requestAnimationFrame call.

 

Using websocket, you don't really need Phaser server-side if you just want to broadcast coordinates or events.

But ...

things aren't so simple

 

Because your online players may have different devices with different framerates, so your game may be run, say, twice faster in a browser as in another one !

And I didn't mention network latency (which is unpredictable because you can't know how your players are connected) which may differ also between end user devices

 

So, if your game doesn't require fine synchronization between players, you could rely on a simple websocket broadcaster.

But, if you need a good synchronization, you will have to run a logic game instance on your server and take in consideration different framesets in client browsers and sometimes anticipate behaviors, collisions, etc because of the network latency. 

Far more complex project !

 

EDIT : old post http://www.html5gamedevs.com/topic/2720-does-phaser-need-to-have-a-canvas-in-order-to-run/?hl=node

Link to comment
Share on other sites

I figured out my "inclusion problem", it was a server matter, I didn't build it correctly, now it's ok.

 

Yes as you said, my game would have to be very precise on latency between players. But for now I will just focus on simple cases. I do it just for fun, but as you said if I want to make it playable on most of the platforms, I'll have to build something against the hardware differences. Thanks anyway for the response.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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