简体   繁体   中英

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

Basically what i have so far is only Console based applications but i found an Example of a 2D game using Lidgren. 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:

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? 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. 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)

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?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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