Advertisement
s1ay3r44

Basic SFML example 1

Apr 2nd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <SFML/Graphics.hpp> // We only need this for all SFML Graphics stuffs
  2.  
  3. using namespace std;
  4.  
  5. void getEvents(sf::RenderWindow& App); // Here we pass App by reference for speed and efficiency
  6.  
  7. int const SCREEN_WIDTH = 800;
  8. int const SCREEN_HEIGHT = 600;
  9.  
  10.  
  11. int main(){
  12.     sf::RenderWindow App(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Our Title");//Makes our window to draw on
  13.     sf::Image img; // Class that holds our image to draw
  14.     sf::Sprite s; // Object we use to draw to the screen
  15.    
  16.     if(!img.LoadFromFile("TheGame.png")) // Returns false if image fails to load
  17.         return 0; // Kills our program if an error is thrown
  18.     s.SetImage(img); // Sets up our sprite to draw
  19.    
  20.     while(App.IsOpened()){
  21.         getEvents(App); // Get our window events (Closing, resizing, etc)
  22.        
  23.         //Inputs are another thing I'll refer you to tutorials about
  24.        
  25.         App.Clear(); // Clear window
  26.         App.Draw(s); // Draw our sprite
  27.         App.Update(); // Update our window
  28.        
  29.     }
  30.     return 0;
  31. }
  32.  
  33. void getEvents(sf::RenderWindow& App){
  34.     Event e;//Event object for our window
  35.    
  36.     while(App.GetEvent(e)){
  37.         if(e.Type == sf::Event::Close) // If our window closes
  38.             App.Close(); // Close our window
  39.        
  40.     }
  41.    
  42.     return;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement