Skip to content

Instantly share code, notes, and snippets.

@mantognini
Created January 5, 2012 16:08
Show Gist options
  • Select an option

  • Save mantognini/1565899 to your computer and use it in GitHub Desktop.

Select an option

Save mantognini/1565899 to your computer and use it in GitHub Desktop.
pong.cpp épuré pour faire ressortir le bug d'affichage
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Define some constants
const int gameWidth = 800;
const int gameHeight = 600;
// Create the window of the application
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
window.EnableVerticalSync(true);
// Load the text font
sf::Font font;
if (!font.LoadFromFile("resources/sansation.ttf"))
return EXIT_FAILURE;
// Initialize the pause message
sf::Text pauseMessage;
pauseMessage.SetFont(font);
pauseMessage.SetCharacterSize(40);
pauseMessage.SetPosition(170.f, 150.f);
pauseMessage.SetColor(sf::Color::White);
// COMMENT NEXT LINE TO REMOVE "DISPLAY-BUG"
pauseMessage.SetString("Welcome to SFML pong!\nPress space to start the game");
pauseMessage.SetString("You lost !\nPress space to restart or\nescape to exit");
while (window.IsOpened())
{
// Handle events
sf::Event event;
while (window.PollEvent(event))
{
// Window closed or escape key pressed: exit
if ((event.Type == sf::Event::Closed) ||
((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape)))
{
window.Close();
break;
}
}
// Clear the window
window.Clear(sf::Color(50, 200, 50));
// Draw the pause message
window.Draw(pauseMessage);
// Display things on screen
window.Display();
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment