Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    11
  • comments
    0
  • views
    248

Multiplayer with Web Sockets

Sign in to follow this  
jhocking

473 views

Still haven’t had much to blog about lately, so this may be a short post. I didn’t even make a post last month, but there were a couple interesting new techniques I’ve been mastering since my last post. One is using the stencil buffer in custom shaders, and the other is using web sockets to implement multiplayer.

If you are new to the concept, the stencil buffer is simply another array of pixels you can draw to, just like the color and depth buffers. As the name implies, it’s useful for drawing stencil masks. As in, you can draw a shape on the stencil buffer, and then have that shape cut out of subsequent render passes.

I found this to be really useful for rendering UI elements in the scene. In my case, I wanted lines drawn on top of the ground that appeared under other objects. What I did was simply draw the silhouette of objects into the stencil buffer while rendering those objects. Then I drew the lines last, on top of everything, but cutting out the silhouettes in the stencil buffer. Perfect!


As for multiplayer using web sockets, there’s not a ton for me to explain, other than that it was super fun to implement. The server is written in Node.js (here’s one simple explanation of how) while the Unity client simply uses a C# web sockets library. I’ve been using this library, but as that link says it’s been deprecated, so I might switch to this library, or even drop some money on this very highly rated asset.

Then I simply send JSON strings back and forth over the sockets. The messages are as simple as a “type” field so the receiver (client or server) can tell what to do with a given message, and then a “payload” field with the data they respond to.

I gotta say, building this has been very interesting. Right now as I type this, I’m suddenly having an idea where a community of players are all interacting live in a mostly text-based game. hm I just described a MUD didn’t I? I wonder if an ad-supported MUD would do well on mobile…


View the full article

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!