1
Graphics / Re: [C++] Moon and Stairs shift ?
« on: April 12, 2013, 11:55:02 pm »
How can i calculate the new Position ?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
void Main::Loop(){
while(Run){
if(Selector.wait()){
if(Selector.isReady(Server)){
sf::TcpSocket* User = new sf::TcpSocket;
if(Server.accept(*User) == sf::Socket::Done){
sUser *theUser = new sUser;
theUser->Client = User;
theUser->State = 0;
theUser->Remove = false;
UserList.push_back(theUser);
Selector.add(*User);
cout << "User connected" << endl;
}
}else{
for(std::list<sUser*>::iterator it = UserList.begin(); it != UserList.end(); ++it){
sUser& User = **it;
if(Selector.isReady(*User.Client)){
sf::Packet Data;
sf::TcpSocket::Status State = User.Client->receive(Data);
if(State == sf::Socket::Done){
HandleData(Data,User);
}else if(State == sf::Socket::Disconnected){
User.Remove = true;
PublicMessage(User.ClientName + " has left the Chat.");
}else if(State == sf::Socket::Error){
cout << "Error" << endl;
}
}
}
UserList.remove_if(CanRemove);
}
}
}
}
Selector.remove(*User.Client);
Selector.add(*theUser->Client);
for(std::list<sUser*>::iterator it = UserList.begin(); it != UserList.end(); ++it){
if(Selector.isReady(*User.Client)){
sf::Packet Data;
if(User.Client->receive(Data) == sf::Socket::Done){
HandleData(Data,User);
}
}
}
for(int x = 0; x != 100; x++){
sf::Image *Chunk = new sf::Image;
Chunk->Create(1000,1000);
}
Chunk->Copy(Exampleimage,X,Y,IntRect(0,0,Exampleimage.GetWidth(),Exampleimage.GetHeight()),true);
Texture *tChunk = new Texture;
tChunk->LoadFromImage(Chunk,IntRect(0,0,1000,1000));
Sprite *sChunk = new sf::Sprite(*tChunk);
sChunk->SetOrigin(0,0);
sChunk->SetPosition(sf::Vector2f((float)xCount,(float)yCount));
BackgroundChunks.push_back(sChunk);
xCount += 1000;
xCounter++;
if(xCount == 5000){
xCount = -5000;
yCount += 1000;
xCounter = 0;
yCounter++;
}
for(list<sf::Sprite*>::iterator IT = BackgroundChunks.begin(); IT != BackgroundChunks.end(); IT++){
_RenderWindow->Draw(**IT);
}