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;
}