简体   繁体   English

C#Lidgren-发送位置和球员状态吗?

[英]C# Lidgren - Send positions and playerstates?

Heey, i've been looking alot on Lidgren, and i've managed to get some simple console client and servers, but i'm having a really hard time with 2D... 嘿,我一直在Lidgren上寻找很多东西,并且设法获得一些简单的控制台客户端和服务器,但是使用2D确实很难。

Basically what i have so far is only Console based applications but i found an Example of a 2D game using Lidgren. 到目前为止,基本上我只有基于控制台的应用程序,但是我发现了一个使用Lidgren的2D游戏示例。 You opened a server, and then two applications. 您打开了一个服务器,然后打开了两个应用程序。 They connected automatically and you could play with the two windows, seeing the character move in the other screen. 它们自动连接,您可以在两个窗口中玩,看到角色在另一个屏幕中移动。 That project used an array to load the textures and in the Draw() method it simple draws the array, but using a value from: 该项目使用数组加载纹理,并在Draw()方法中简单地绘制数组,但是使用来自以下项的值:

foreach (var kvp in positions)
{
   // use player unique identifier to choose an image
   int num = Math.Abs((int)kvp.Key) % textures.Length;`
   // draw player
   spriteBatch.Draw(textures[num], kvp.Value, Color.White);
}

Could someone explain what that num variable does? 有人可以解释num变量的作用吗? And if i wanted to use diffrent classes to do this, would i simply just do the same but in the player classes, and also, animations - how do you send texture update data?? 如果我想使用不同的类来做到这一点,我会只是在播放器类以及动画中做同样的事情—如何发送纹理更新数据? Sorry that i'm asking so much..but i haven't found anything that actually helps :/ 对不起,我问的太多了..但是我还没有找到真正有用的东西:/

Thanks in advance and if you need to know something else, tell me! 在此先感谢您,如果您需要了解其他信息,请告诉我! :) :)

The num variable simply chooses a unique texture, that will always be the same, from the textures array. num变量仅从textures数组中选择一个始终相同的唯一纹理。 Say you have 4 textures, but the Key the modulo operator ( % ) will get the remainder of 7/4 , which would be 3. Basically it would wrap it around the amount of textures, because they would have to repeat (Ex, Id 4 and Id 8 have the same textures) 假设您有4个纹理,但是Key模运算符% )将得到7/4的余数,即3。基本上,它将包裹纹理数量,因为它们必须重复(例如,Id 4和ID 8具有相同的纹理)

For now you can just use a static texture, but you can use the same code to choose a texture variation. 目前,您只能使用静态纹理,但是可以使用相同的代码选择纹理变体。

What do you mean texture update data? 您是什么意思纹理更新数据? Such as changing textures, or updating positions? 例如更改纹理或更新位置? If changing textures, is the texture known or not? 如果更改纹理,是否知道纹理? (Ex, can an ID/name be sent, or does the data have to?) (例如,可以发送ID /名称,还是必须发送数据?)

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

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