Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - MartinVilche

Pages: [1]
1
General / Re: Drawing Lists of RectangleShapes.
« on: July 09, 2017, 01:59:09 am »
Each node in a list should point to the next one. At no time are you setting next to anything but null.

Is there a reason that you aren't just using std::list or std::forward_list?

I just prefer using pointers myself.
I thought that if i called "r = new Node" when r is pointing at NULL, it would create a new Node pointer.
I will try to learn and use std::list.
Thx

2
General / Drawing Lists of RectangleShapes.
« on: July 09, 2017, 12:34:38 am »
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;
}
 

Pages: [1]
anything