Java libgdx(desktop/android)多人游戏怎么玩
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16720436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java libgdx(desktop/android) multiplayer game how to
提问by csga5000
I have a game called wizard wars that I have been working on. This game needs to allow 2 players to play at one time, and would need a TCP connection to communicate spell creation/destruction ect., and a UDP connection to handle locations ect. It would have a client and a host side. That being said my program is designed to run on Android. All of the tutorials/information I have found online has been for JApplets or something like that. So what I would like is some help with ever short code examples of how to set up/use connections, or just a link to some sufficiently helpfull information on how to set up the actual connections.
我一直在开发一款名为“巫师War”的游戏。该游戏需要允许 2 名玩家同时玩,并且需要 TCP 连接来通信法术创建/破坏等,以及 UDP 连接来处理位置等。它将有一个客户端和一个主机端。话虽如此,我的程序旨在在 Android 上运行。我在网上找到的所有教程/信息都是针对 JApplet 或类似内容的。所以我想要的是一些关于如何设置/使用连接的简短代码示例的帮助,或者只是一个链接到一些关于如何设置实际连接的足够有用的信息。
采纳答案by pedronveloso
The best approach (or at least 1 approach) would be to use normal HTTP requests : http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html
最好的方法(或至少一种方法)是使用普通的 HTTP 请求:http: //libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html
You create a webservice implementing REST and create calls for both updating and consuming data.
您创建了一个实现 REST 的网络服务,并为更新和使用数据创建调用。
Alternatively, if you're just going to use Android and Desktop you may also use WebSockets : https://github.com/pepedeab/libGDX-Net
或者,如果您只想使用 Android 和桌面,您也可以使用 WebSockets :https: //github.com/pepedeab/libGDX-Net
回答by Ghandhikus
For those who don't read comments, but still looking for tcp client.
对于那些不阅读评论但仍在寻找 tcp 客户端的人。
You can use KryoNet which supports Desktop and Android https://github.com/EsotericSoftware/kryonet
您可以使用支持桌面和安卓的 KryoNet https://github.com/EsotericSoftware/kryonet
回答by dhruv chopra
Have you guys looked at the multiplayer super jumper tutorial? Its written using AppWarp and is being actively used in the libgdx community as well.
你们看过多人超级跳投教程吗?它使用 AppWarp 编写,并且也在 libgdx 社区中得到积极使用。