When player gets ID-0 he always receives the position of himself and the other player which causes his position to flicker between his actual one and the other players each frame. I've been going through the code multiple times and can't understand why it's doing that.
Any help would be greatly appreciated.
CLIENT CODE -
https://hastebin.com/kukiyabopu.phpSERVER CODE -
https://hastebin.com/ceboyawobi.cppserver -
if (socket.receive(player1Pac, clients[0].address, clients[0].port) == sf::Socket::Done)
{
sf::Vector2i pos;
//player1Pac >> pos.x >> pos.y;
socket.send(player1Pac, clients[1].address, clients[1].port);
//cout << "Sent info to player 2" << endl;
player1Pac.clear();
}
// send player 2 data to player 1
if (socket.receive(player2Pac, clients[1].address, clients[1].port) == sf::Socket::Done)
{
sf::Vector2i pos2;
//player2Pac >> pos2.x >> pos2.y;
socket.send(player2Pac, clients[0].address, clients[0].port);
//cout << "Sent info to player 1" << endl;
player2Pac.clear();
}
client -
if (myID == 1)
{
//cout << "myID: " << myID << endl;
//cout << "player 2 pos:" << OtherX << ":" << OtherY << endl;
//system("cls");
Players[1].setPosition(Xposition, Yposition);
Players[0].setPosition(OtherX, OtherY);
}
else if (myID == 0)
{
//cout << "myID: " << myID << endl;
//cout << "player 1 pos:" << OtherX << ":" << OtherY << endl;
//system("cls");
Players[0].setPosition(Xposition, Yposition);
Players[1].setPosition(OtherX, OtherY);
}