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

Author Topic: The window flashes black  (Read 2594 times)

0 Members and 1 Guest are viewing this topic.

supperpiccle

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
The window flashes black
« on: July 26, 2012, 05:25:56 pm »
I am making a game that when opened will display a menu but when my program goes through the loop it flashes that pic and black....here is my code
sf::Event Event;

    while(rw.IsOpened())
    {
        while(rw.GetEvent(Event))
       {
           if(Event.Type==sf::Event::Closed)
           rw.Close();
           //close window//
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            rw.Close();
            //Esc key//

       }
rw.Display();
    }

and yes i have drawn all the sprites to the window this is just where the problem is

What am i doing wrong?
« Last Edit: July 26, 2012, 05:28:32 pm by supperpiccle »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The window flashes black
« Reply #1 on: July 26, 2012, 05:28:24 pm »
What am i doing wrong?
Not calling rw.clear();, not drawing anything and not explaining enough/showing enough code of your problem. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

supperpiccle

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: The window flashes black
« Reply #2 on: July 26, 2012, 05:29:44 pm »
MainMenu::MainMenu(sf::RenderWindow & rw)
{
    sf::Image Main_Menu_Pic;
    Main_Menu_Pic.LoadFromFile("MasterSprites/MainMenu/MainMenu.png"); //this is the Main Menu
    sf::Sprite Main_Menu_Sprite(Main_Menu_Pic);
    int i=0;
    int n=0;

    bool running=true;

    Button button[3];
    //-------------------------------
    button[0].x=263;
    button[0].y=125;
    button[0].Set_Pic_Without_Border("MasterSprites/MainMenu/PGWithoutBorder.png");
    button[0].Set_Pic_With_Border("MasterSprites/MainMenu/pg Border.png");
    //play button init

    button[1].x=290;
    button[1].y=184;
    button[1].Set_Pic_Without_Border("MasterSprites/MainMenu/c WithoutBorder.png");
    button[1].Set_Pic_With_Border("MasterSprites/MainMenu/c Border.png");
    //Credits button init

    button[2].x=267;
    button[2].y=245;
    button[2].Set_Pic_Without_Border("MasterSprites/MainMenu/qg WithoutBorder.png");
    button[2].Set_Pic_With_Border("MasterSprites/MainMenu/qg Border.png");
    //quit game button init







    rw.Draw(Main_Menu_Sprite);
    rw.Draw(button[0].Button_Without_Border);
    rw.Draw(button[1].Button_Without_Border);
    rw.Draw(button[2].Button_Without_Border);

   //complete init now it is almost up without user interaction

sf::Event Event;

    while(rw.IsOpened())
    {
        while(rw.GetEvent(Event))
       {
           if(Event.Type==sf::Event::Closed)
           rw.Close();
           //close window//
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            rw.Close();
            //Esc key//

       }
rw.Display();
    }








}




 

this is all of it i have tried clear but it just makes the screen black the whole time

supperpiccle

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: The window flashes black
« Reply #3 on: July 26, 2012, 05:30:53 pm »
button is my class i made

supperpiccle

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: The window flashes black
« Reply #4 on: July 26, 2012, 05:40:59 pm »
MainMenu::MainMenu(sf::RenderWindow & rw)
{
    sf::Image Main_Menu_Pic;
    Main_Menu_Pic.LoadFromFile("MasterSprites/MainMenu/MainMenu.png"); //this is the Main Menu
    sf::Sprite Main_Menu_Sprite(Main_Menu_Pic);
    int i=0;
    int n=0;

    bool running=true;

    Button button[3];
    //-------------------------------
    button[0].x=263;
    button[0].y=125;
    button[0].Set_Pic_Without_Border("MasterSprites/MainMenu/PGWithoutBorder.png");
    button[0].Set_Pic_With_Border("MasterSprites/MainMenu/pg Border.png");
    //play button init

    button[1].x=290;
    button[1].y=184;
    button[1].Set_Pic_Without_Border("MasterSprites/MainMenu/c WithoutBorder.png");
    button[1].Set_Pic_With_Border("MasterSprites/MainMenu/c Border.png");
    //Credits button init

    button[2].x=267;
    button[2].y=245;
    button[2].Set_Pic_Without_Border("MasterSprites/MainMenu/qg WithoutBorder.png");
    button[2].Set_Pic_With_Border("MasterSprites/MainMenu/qg Border.png");
    //quit game button init







    rw.Draw(Main_Menu_Sprite);
    rw.Draw(button[0].Button_Without_Border);
    rw.Draw(button[1].Button_Without_Border);
    rw.Draw(button[2].Button_Without_Border);

   //complete init now it is almost up without user interaction

sf::Event Event;

    while(rw.IsOpened())
    {
        while(rw.GetEvent(Event))
       {
           if(Event.Type==sf::Event::Closed)
           rw.Close();
           //close window//
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            rw.Close();
            //Esc key//

       }
rw.Display();
    }








}




 my code flashes between the pic and black.....whats up with it....button is my class btw

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The window flashes black
« Reply #5 on: July 26, 2012, 05:47:17 pm »
For this you now had to make 4 posts split in 2 topics?  >:(  :o

It's obvious what the problem is.
You only draw the sprites once. You have to put the draw calls with in the game loop, like in all the SFML examples you'll ever find. ;)
And you should call rw.clear() every iteration.
« Last Edit: July 26, 2012, 05:49:48 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

supperpiccle

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: The window flashes black
« Reply #6 on: July 26, 2012, 05:58:25 pm »
I am extremely sorry about how that turned out...yea i figgured it out by myself....i thought that the first thread was ignored so i thought well ill just make a new thread but accedently put it in this one.....im sorry thanks tho!!

 

anything