Hello, I'm doing some test on SFML to know how the Engine of the game I'm making will work and i found a problem:
When I try to draw the elements on a list of shapes it only draws the first one.
int main(){
sf::RenderWindow window(sf::VideoMode(640,480), "TESTING", sf::Style::Default);
window.setFramerateLimit(60);
window.setKeyRepeatEnabled(false);
struct Node{
sf::RectangleShape rect;
Node* next;
};
int q = 0;
Node* list = NULL;
Node* d = list;
Node* r = list;
sf::Event event;
while(window.isOpen()){
while(window.pollEvent(event))
if(event.type == sf::Event::Closed)
window.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){
r = list;
while(r != NULL){
printf("in loop\n");
r = r->next;
}
if(r == list){
list = new Node;
printf("created a new one. (first one)\n");
list->rect.setSize(sf::Vector2f(25,25));
list->rect.setPosition(25*q,25*q);
q++;
list->next = NULL;
}
else if(r == NULL){
r = new Node;
printf("created a new one.\n");
r->rect.setSize(sf::Vector2f(25,25));
r->rect.setPosition(25*q,25*q);
q++;
r->next = NULL;
}
}
window.clear();
while(d != NULL){
window.draw(d->rect);
d=d->next;
}
if(d == NULL)
d = list;
window.display();
}
return 0;
}