开发者

How to code an web-browser based multiplayer game?

If I wanted to code a desktop-based game, I could pull some XNA code and UDP sockets and make a decent multiplayer game. I would have an extremely clear of how to code the game I wanted.

But if I wanted to code a browser-based online multiplayer game, how would I do it? You can't use XNA....I've been looking a开发者_开发知识库t some questions and I'm seeing PHP and ASP.NET and Silverlight and Flash and Java as the alternative languages...I really don't understand how it works. I mean, for a desktop-based game, you're opening a UDP socket and accepting clients and transferring data, updating player states, drawing the results using XNA. But in a browser, how do you open a socket and stuff? How does that concept work, communicating to people in realtime through a web-browser. Any direction? I'm familiar with C#, and semi-familiar with Java. Never done any Flash, ASP.NET or Silverlight.


The paradigm is a bit different. In a browser-based game, the game state is stored and computed on the server. All the user sees is a user interface that pulls data from this single game state.

Player 1 has a spaceship at location 34,29. He presses forward and goes to 35,30. This gets sent to the server with something like AJAX. Other players see this change when they query the web server for other players' locations. This location needs to be stored somewhere on that server in order for this to happen.

Think about the difference between Google docs and Microsoft Word. One has the document on your computer, the other is storing the document online and you are simply interacting with some distant HTTP server.


For the UI, you will probably get best results with Silverlight or Flash, followed by Java. As far as multiplayer interaction, you could use web services to send and receive data rather than UDP/socket communications.

Since you're already familiar with C#, you can leverage that knowledge with both Silverlight and web services so there's somewhat less to learn.


Since you are familiar with C# and semi-familiar with Java, my best guess would be Unity3D for the client side code (that runs in the browser) and SmartfoxServer for the server side code.

Unity3D is a powerful game engine that can be used to produce games that run in the browser. You can code your game using Javascript or C#. SmartfoxServer is a multiplayer game server written in Java that provides a simple and flexible API for communication.

Combining both you can create amazing 2D/3D multiplayer games.


There are almost as many solutions as there are browser-based games. Flash can do it, it's probably possible with php and ajax, you could always use Java. It depends on what you're already familiar with.


When you program a desktop game, the game is in the player's computer. When you program a web-browser based game, the game is NOT in the player's computer but in YOUR server. All the player can see in her browser is the UI. So, you must program all the logic of your game in the server side and only the interface in the client side.

It helps if you think of the browser like a monitor on steroids.

And about the UDP/sockets... there is not such thing in web apps, but you can still use Asynchronous Requests, via AJAX or FLASH (I'm not pretty sure if flash can do Async, bot I'd bet it can).

So, instead of a keyboard -> program -> monitor flow you have a keyboard -> browser-scripts -> AJAX request -> server-scripts -> monitor flow.


You might want to take a look at web sockets in HTML5. Depending on what kind of game you want to make, pure HTML5 using Canvas and some javascript library like JQuery might be just what you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜