简体   繁体   English

Kryonet和Slick2D

[英]Kryonet and Slick2D

I'm trying to integrate Kryonet within a Slick2D game with the assistance of this tutorial . 我正在尝试在本教程的帮助下将Kryonet集成到Slick2D游戏中。 I'm trying to create a server/client infrastructure where a user can either create a server or join a server to play a two player game. 我正在尝试创建一个服务器/客户端基础结构,用户可以创建服务器或加入服务器来玩双人游戏。

The tutorial suggests adding the overall game object as a "network listener," however in my Slick2D game the GameContainer and StateBasedGame are only available across the whole application. 本教程建议将整个游戏对象添加为“网络监听器”,但在我的Slick2D游戏中,GameContainer和StateBasedGame仅在整个应用程序中可用。

The GameContainer wraps my game object and this game object extends StateBasedGame. GameContainer包装我的游戏对象,这个游戏对象扩展了StateBasedGame。 I have no idea how to integrate KryoNet. 我不知道如何整合KryoNet。

I'm really struggling to find info that can help me so any guidance at all would be great. 我真的很难找到可以帮助我的信息,所以任何指导都会很棒。

You should create a GameServer class and a GameClient class. 您应该创建一个GameServer类和一个GameClient类。 Game logic goes in GameServer and rendering goes in GameClient. 游戏逻辑进入GameServer,渲染进入GameClient。 If your game logic is mixed with your rendering code, take a look at some model view controller explanations (here's a decent article: http://www.badlogicgames.com/wordpress/?p=2668 ). 如果您的游戏逻辑与渲染代码混合在一起,请查看一些模型视图控制器解释(这是一篇不错的文章: http//www.badlogicgames.com/wordpress/? p = 2668 )。

Let me tell you that usually the server and client are completely different applications and sometimes it isn't feasable to let the users host the server because it might involve configuring firewalls and whatnot. 让我告诉你,通常服务器和客户端是完全不同的应用程序,有时让用户托管服务器是不可行的,因为它可能涉及配置防火墙等等。

So GameServer should extend Listener, create an instance of kryonet's Server, and add itself as a listener to the server. 所以GameServer应该扩展Listener,创建一个kryonet Server的实例,并将自己添加为服务器的监听器。 GameClient should similarly extend Client, create an instance of kryonet's Client, and add itself as a listener to the client. GameClient应该类似地扩展Client,创建kryonet的Client实例,并将自己添加为客户端的监听器。

If you pass a reference of the current game state class to the GameClient, the GameClient can communicate to it and tell it what to render and then the game state can tell the client what to send as input. 如果您将当前游戏状态类的引用传递给GameClient,GameClient可以与它通信并告诉它要呈现什么,然后游戏状态可以告诉客户端要作为输入发送什么。 Similarly, if you pass a reference of the current game state class to the GameServer, the server can provide input to the game logic and then the game logic can tell the server what to send to the clients. 类似地,如果您将当前游戏状态类的引用传递给GameServer,则服务器可以向游戏逻辑提供输入,然后游戏逻辑可以告诉服务器将什么发送给客户端。

I would recommend creating a simple message passing program on IP loopback to get familiar with kryonet. 我建议在IP环回上创建一个简单的消息传递程序,以熟悉kryonet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM