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

Author Topic: Problem with rendering a rectangle  (Read 1521 times)

0 Members and 1 Guest are viewing this topic.

C0dedSurvivor

  • Newbie
  • *
  • Posts: 10
    • View Profile
Problem with rendering a rectangle
« on: January 26, 2016, 06:54:41 pm »
For some reason this code won't render the rectangleshape correctly. It takes control away from the player correctly and waits the right amount before giving it back, but the rectangle doesn't render on the window. If you need more of my code, please let me know.

int screenHeight = 500;
int screenWidth = 500;

if (Keyboard::isKeyPressed(Keyboard::Escape)){
                  playerControl = false;
                  RectangleShape menuBackground;
                  menuBackground.setFillColor(sf::Color::Red);
                  menuBackground.setSize(Vector2f(0, 0));
                  menuBackground.setPosition(sf::Vector2f(screenWidth / 2, screenHeight / 2));
                  window.draw(menuBackground);
                  for (int c = 1; c < 51; c++){
                     menuBackground.setSize(sf::Vector2f(round(screenWidth / 50) * c, round(screenHeight / 50) * c));
                     menuBackground.move(sf::Vector2f((round(screenWidth / 50) * c / 2) * -1, round((screenHeight / 50) * c / 2) * -1));
                     window.draw(menuBackground);
                     sleep(Time(milliseconds(10)));
                  }
                  menuBackground.setSize(Vector2f(screenWidth, screenHeight));
                  window.draw(menuBackground);

                  sleep(Time(seconds(3)));
                  
                  for (int a = 0; a < 50; a++){
                     menuBackground.setSize(sf::Vector2f(screenWidth - (round(screenWidth / 50) * a), screenHeight - (round(screenHeight / 50) * a)));
                     menuBackground.move(sf::Vector2f(round(screenWidth / 50) * a / 2, round(screenHeight / 50) * a / 2));
                     window.draw(menuBackground);
                     sleep(Time(milliseconds(10)));
                  }
                  menuBackground.setSize(Vector2f(0, 0));
                  window.draw(menuBackground);
                  playerControl = true;
            }

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Problem with rendering a rectangle
« Reply #1 on: January 26, 2016, 06:56:32 pm »
You show you're using of window.draw(), but nowhere in this code is window.clear() or window.display(). Do you have clear() happening before drawing in your game loop and display() happening immediately after?

C0dedSurvivor

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Problem with rendering a rectangle
« Reply #2 on: January 26, 2016, 07:14:01 pm »
Thank you, I knew there was something simple I was forgetting...

 

anything