Jump to content

Phaser with Socket.IO


Ralph
 Share

Recommended Posts

Hi there, so i built a fairly functional open world multiplayer game, however, when I first started building it, i built it as a singe player game and set up the variables and things i will need to be sent from the server in a way that it will easy to be converted into multiplayer. Today I dove into that adventure and right off the bat I am having issues with phaser and nodejs. To be insanely clear because any other thread I have found about this topic thinks everyone wants to do this, I do NOT want to run phaser on the server side, I just want to be able to use socket.io in my game and I cant right now since my game wont even load.

 

This is the error it throws when I load my page, no matter what I do, always "Phaser is not defined"

GET http://xxx.xxxx.xxx/assets/phaser.js 404 (Not Found)
(index):214 Uncaught ReferenceError: Phaser is not defined

 

My server that I am running on node:

var express = require('express');
var app = express();


app.use(express.static('public'));

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

app.listen(80, function () {
  console.log('Example app listening on port 80!');
});

 

I removed socket.io from it until I can actually get my index.html to load. I believe i have to use static directories, and I believe it works because I can load all the images from my assets directory (where phaser.js is) fine form my browser. In my index.html, phaser is called in my header as shown: 

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

 

Am I doing something wrong? ANY help is appreciated. I dont care how I get to the end product, I just want to be able to have a server side connection from every client to send and recieve variables on connection/disconnection. Before I switched to node, I was just using an apache server to run my index.html. Thanks for any help!

P.s: Could this be a problem with express? I havent tried it with a standard node http server.

Link to comment
Share on other sites

6 hours ago, drhayes said:

Can you load phaser.js from your public/assets/phaser.js folder by typing its address into the browser? Is your script tag with phaser declared before the script tag with your game?

No i cant load anything from the directory in my browser. Yes phaser is called perfectly fine, the game works fine on apache, just not on node.

Link to comment
Share on other sites

Just copied your server file verbatim and ran it (I'm running on 3000, nginx is on 80 and node needs a bit of fiddling to be privileged to work on 80 anyway I think, you wouldnt normally want node on 80 anyway), phaser loads just fine, its probably just an issue with your directory structure

Using relative or absolute path to phaser doesn't matter of course, but for completeness, its loading from browser thus

<script src="assets/phaser.js"></script>

 

Screen Shot 2016-07-08 at 12.21.18.png

Screen Shot 2016-07-08 at 12.21.44.png

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...