Game Development Reference
In-Depth Information
1. Update the remote shape if a new packet with information has come in.
2. Update our local shape from the position vector and send the new position over
the other side.
This is how we achieve that behavior:
First we check for any new packets coming our way. If there is a packet waiting, we un-
pack its information (only a position in this example) in a Vector2f instance and set the
position of the remote shape (the shape of the other client) to that position.
After we have updated the remote shape, it is time to handle our own. First we check if we
have to move at all. If we don't have to move, we don't have to update the position of our
shape and thus don't have to send a packet over. This prevents any unnecessary data being
transferred over the network. However, if our shape has to move due to the input, we
move the shape itself and compose a packet of its position. The last step is to send it over
to the other side. There might be a problem with sending it—the other side might not be
responding due to disconnection, internet problems, and so on. In this, we assume that it's
a disconnection problem and exit the program.
Search WWH ::




Custom Search