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

Author Topic: White screen  (Read 1823 times)

0 Members and 1 Guest are viewing this topic.

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
White screen
« on: October 07, 2012, 08:32:07 pm »
Another problem I have meeted today  ??? . My screen when my run the code is white, nothing happen only the sound is working and the [ESC] button.
///////////////
/// Headers ///
///////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>

///////////////

////////////
/// Code ///
////////////
int main()
{
    /////////////////////////
    // Declarare variabile //
    /////////////////////////
    sf::Vector2f playersize(50,50); // Marimea jucatorului
    bool isPlaying = false; // Variabila de verificare a desfasurarii jocului
    /////////////////////////

    //////////////////////
    // Creare fereastra //
    //////////////////////
    sf::RenderWindow window(sf::VideoMode(800,600),"Moving System");
    //////////////////////

    /////////////
    // Fonturi //
    /////////////
        // Font general
    sf::Font font;
    if (!font.loadFromFile("resources/VIKING-N.ttf")) return -1;
    /////////////

    /////////////////////
    // Muzica & Sunete //
    /////////////////////
        // Muzica
            // Muzica de background
                // Background Music 1
    sf::Music bcgmsc1;
    if(!bcgmsc1.openFromFile("resources/backgroundmusic.ogg")) return -1;
    bcgmsc1.play();

        // Sunete

    /////////////////////

    // Creare jucator
    sf::RectangleShape player;
    player.setSize(playersize);
    player.setOutlineThickness(3);
    player.setOutlineColor(sf::Color::Black);
    player.setFillColor(sf::Color::Blue);
    player.setOrigin(playersize / 2.f);


    ////////////
    // Mesaje //
    ////////////
        // Mesaj general
    sf::Text message;
    message.setCharacterSize(40);
    message.setFont(font);
    message.setPosition(100, 15);
    message.setColor(sf::Color::Red);
    message.setString("Antic Pong");
    ////////////

    // Actiune
    sf::Clock clock;
    while (window.isOpen())
    {
        sf::Event event;

        while (window.pollEvent(event))
        {
            // Metoda de inchidere
            if ((event.type == sf::Event::Closed) ||
               ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
            {
                window.close();
                break;
            }

            if((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
            {
                if(!isPlaying)
                {
                    isPlaying=true;
                    clock.restart();

                    // Resetare pozitie jucator
                    player.setPosition(30,30);
                }
            }
        }

        if (isPlaying)
        {
            // Miscarea jucatorului
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
                player.move(30,40);
            }
        }

        // Sterge fereastra
        window.clear(sf::Color::Green);

        // Afisare
        if(isPlaying)
        {
            window.draw(player);
        }
        else
        {
            window.draw(message);
        }
    }

    return 0;
}
 
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
Re: White screen
« Reply #1 on: October 07, 2012, 08:40:03 pm »
You forgot window.display() at the end.

 

anything