Hello everybody, I am coding one simple application and I have a problem with this code :
#include<SFML/Graphics.hpp>
#include<SFML/Network.hpp>
#include<iostream>
#include<string>
#include"Naruto.h"
using namespace sf;
using namespace std;
int main(void)
{
RenderWindow app(VideoMode(800,600,32),"Naruto");
TcpSocket mySocket;
bool connexion(true);
while(connexion)
{
if(mySocket.Connect("192.168.1.176",5000) == Socket::Done)
connexion = false;
}
Naruto naruto("Image/NarutoNormal.bmp");
naruto.changerPosition(400,100);
Naruto sakura("Image/SakuraNormal.bmp");
sakura.changerPosition(400,400);
Texture terrTxt;
terrTxt.LoadFromFile("Image/terrain.bmp");
Sprite terrain;
terrain.SetTexture(terrTxt);
while(app.IsOpen())
{
Event event;
while(app.PollEvent(event))
{
if(event.Type == Event::Closed)
app.Close();
Packet paquet;
if(Keyboard::IsKeyPressed(Keyboard::Up))
{
naruto.avancer();
paquet << "haut";
mySocket.Send(paquet);
paquet.Clear();
}
if(Keyboard::IsKeyPressed(Keyboard::Down))
{
naruto.reculer();
paquet << "bas";
mySocket.Send(paquet);
paquet.Clear();
}
if(Keyboard::IsKeyPressed(Keyboard::Left))
{
naruto.allerAGauche();
paquet << "gauche";
mySocket.Send(paquet);
paquet.Clear();
}
if(Keyboard::IsKeyPressed(Keyboard::Right))
{
naruto.allerADroite();
paquet << "droite";
mySocket.Send(paquet);
paquet.Clear();
}
string myText("");
if(mySocket.Receive(paquet))
{
paquet >> myText;
}
}
app.Clear();
app.Draw(terrain);
app.Draw(naruto.getPersonnage());
app.Draw(sakura.getPersonnage());
app.Display();
}
return EXIT_SUCCESS;
}
The probleme is at the reception of a packet just before clearing the window etc...
My window is always "transparent" , it did not display what he does.
I think, and I know that there is a problem in the reception of a packet, but what ? Even if i don't write anything in this condition.