如何编写基于网络浏览器的多人游戏?

发布于 2024-09-07 12:36:17 字数 366 浏览 2 评论 0原文

如果我想编写一款基于桌面的游戏,我可以提取一些 XNA 代码和 UDP 套接字并制作一款不错的多人游戏。我会非常清楚如何编写我想要的游戏。

但如果我想编写一个基于浏览器的在线多人游戏,我该怎么做呢?你不能使用 XNA...我一直在研究一些问题,我看到 PHP 和 ASP.NET、Silverlight、Flash 和 Java 作为替代语言...我真的不明白它是如何工作的。我的意思是,对于基于桌面的游戏,您要打开 UDP 套接字并接受客户端并传输数据、更新玩家状态、使用 XNA 绘制结果。但是在浏览器中,如何打开套接字之类的东西?这个概念是如何运作的,通过网络浏览器与人们实时交流。有什么方向吗?我熟悉C#,半熟悉Java。从未接触过任何 Flash、ASP.NET 或 Silverlight。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

清风挽心 2024-09-14 12:36:17

范式有点不同。在基于浏览器的游戏中,游戏状态在服务器上存储和计算。用户看到的只是一个从该单一游戏状态中提取数据的用户界面。

玩家 1 在位置 34,29 拥有一艘宇宙飞船。他向前推进并到达35,30。这会通过 AJAX 等方式发送到服务器。其他玩家在向网络服务器查询其他玩家的位置时会看到此更改。为了实现这一点,需要将该位置存储在该服务器上的某个位置。

想想 Google 文档和 Microsoft Word 之间的区别。一个将文档存储在您的计算机上,另一个将文档存储在网上,您只需与某个远程 HTTP 服务器进行交互。

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.

洋洋洒洒 2024-09-14 12:36:17

对于 UI,使用 Silverlight 或 Flash 可能会获得最佳结果,其次是 Java。就多人交互而言,您可以使用 Web 服务来发送和接收数据,而不是 UDP/套接字通信。

由于您已经熟悉 C#,因此您可以将这些知识用于 Silverlight 和 Web 服务,因此需要学习的内容会少一些。

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.

生寂 2024-09-14 12:36:17

由于您熟悉 C# 并且半熟悉 Java,我最好的猜测是客户端使用 Unity3D端代码(在浏览器中运行)和 SmartfoxServer 用于服务器端代码。

Unity3D是一个功能强大的游戏引擎,可用于制作在浏览器中运行的游戏。您可以使用 Javascript 或 C# 编写游戏代码。 SmartfoxServer 是一个用 Java 编写的多人游戏服务器,提供简单而灵活的 API 进行通信。

将两者结合起来,您可以创建令人惊叹的 2D/3D 多人游戏。

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.

追我者格杀勿论 2024-09-14 12:36:17

解决方案几乎与基于浏览器的游戏一样多。 Flash 可以做到这一点,使用 php 和 ajax 可能可以做到,您始终可以使用 Java。这取决于您已经熟悉的内容。

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.

深陷 2024-09-14 12:36:17

当您编写桌面游戏时,游戏就在玩家的计算机中。当您编写基于网络浏览器的游戏时,游戏不在玩家的计算机中,而是在您的服务器中。玩家在浏览器中只能看到 UI。因此,您必须在服务器端编写游戏的所有逻辑,而仅在客户端编写界面。

如果您将浏览器视为类固醇监视器,这会有所帮助。

关于 UDP/套接字...网络应用程序中没有这样的东西,但您仍然可以通过 AJAX 或 FLASH 使用异步请求(我不太确定 flash 是否可以异步,我打赌它可以)。

因此,代替键盘 ->程序->监控 流程,您有一个键盘 ->浏览器脚本 -> AJAX请求->服务器脚本 ->监控流量。

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.

长伴 2024-09-14 12:36:17

您可能想看看 HTML5 中的 网络套接字。根据您想要制作哪种类型的游戏,使用 Canvas 和一些 javascript 库(如 JQuery)的纯 HTML5 可能正是您想要的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文