SFML community forums

Help => Graphics => Topic started by: supperpiccle on July 26, 2012, 05:25:56 pm

Title: The window flashes black
Post by: supperpiccle 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?
Title: Re: The window flashes black
Post by: eXpl0it3r 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. ;)
Title: Re: The window flashes black
Post by: supperpiccle 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
Title: Re: The window flashes black
Post by: supperpiccle on July 26, 2012, 05:30:53 pm
button is my class i made
Title: Re: The window flashes black
Post by: supperpiccle 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
Title: Re: The window flashes black
Post by: eXpl0it3r 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.
Title: Re: The window flashes black
Post by: supperpiccle 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!!