Jump to content

Server-sided map with Node.js?


Recommended Posts

I'm quite new to programming with javascript and somewhat new to object-oriented programming in general. I'm trying to create a simple online game using Node.js and Socket.io. I want to use a map system (ideally using the Tiled editor) that can read TMX or JSON files. At first I found Phaser and while the interface is great, I've heard that it's not a good idea to use it for server-sided programming. So I have a couple questions to ask you guys:

1. Are there any tutorials, examples or libraries that can help me parse a TMX/JSON file created with Tiled and use it for my server map? What is the easiest way to go about doing this without the help of Phaser?

2. I've noticed that WebGL seems a lot faster than the HTML canvas. Are there any resources that can help me understand how to use it, or should I stick to using canvas? I know Phaser has this built in, but it seems silly to use it just to render graphics.   

I'd really appreciate any suggestions you guys have. 


Link to comment
Share on other sites

These are super questions.

Phaser is indeed a client side library, as it primarily handles audio/visual and user input that is no surprise (it also has various other helpers such as a state machine and some app logic stuff that might be useful elsewhere, but, largely, its client specific). There have been some efforts to get it running on the server, I'm not too sure on the use case (might just be for testing) but I don't think there was resounding success. I'd assume you can pull bits out of it you wanted elsewhere though.

1. I can't really help you as I don't know, but, poking through Phaser source files will help you see how it does and what it does with the Tiled data format/s, you may even be able to rip those out (using imports, or using Phaser.something, or, even good ole fashioned copy-paste some functions). Largely though the format you choose for your map relies on what you want out of it, I'd have thought Phaser would structure it in a nice way to render it and possibly do collision detection whilst being flexible enough for generic use-cases, you may not want this and may want to transform the json Tiled spits out (or, maybe its nice enough to work with as is and you just need to add some functions?).

2. WebGL is, in almost every case, faster. Also, your option is to either dig through canvas and context objects directly, or, use a wrapper library. Phaser v2.x uses Pixi.js for rendering, and Pixi is *only* really concerned with creating a scene graph so it can render your stuff _really really_ fast. There are alternatives out there also.

Unless you really want to dig through (and learn) how the canvas works then I'd suggest using an off the shelf library to help.

Having said that, https://regl-project.github.io/regl/ is an awesome project! As you said you're new to OOP I thought it might be of interest as its extremely light on OOP and OOP-like stuff.

Link to comment
Share on other sites

Hi man.

1. You would like to have an opportunity sending JSON file to the server, parsing to map and using as a level of other players in your game, right?
If yes, all that you need is to have node.js server (you can use any frameworks, for example Express or Koa), create REST and handle POST with your json data.
Then you need to keep the data somewhere, for example you can save your json file on the server and use next time.
When client will be loaded he need to get parsed JSON data (maybe it will be another json data) and generate game scene (graphics and playable content).

2. WebGL works faster, but it's quite harder to manage, if you are quite new in javascript, maybe better to use engines such as Pixi/Phaser/Three.js. WebGL is not works anywhere, only where context is available (for example not works in PS4, blocked my developers), it can be also less performant on mobile devices. Better to say usually webgl works well on webkit based modern browsers. Beside you need to have well enough math background of Linear Algebra to work with matrices and vectors (in a case if you want to write on pure webgl without libraries). At the end recently I wrote my own rendering engine on WebGL for my own game, I have a twitch where I stream my progress, there you can ask questions. If you want I can share with link.


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.

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.


  • Recently Browsing   0 members

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