Advertisement
Felanpro

events and some examples (SFML)

Mar 19th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Window.hpp>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     sf::Window window(sf::VideoMode(800, 600), "Generic name for a window");
  11.     sf::Event event;
  12.  
  13.     while (window.isOpen())
  14.     {
  15.  
  16.         while (window.pollEvent(event))
  17.         {
  18.             if (event.type == sf::Event::Closed)
  19.                 window.close();
  20.             else if (event.type == sf::Event::KeyPressed)
  21.                 cout << "The player pressed a key" << endl;
  22.             else if (event.type == sf::Event::Resized) //This code gets triggered when the window is resized by the user
  23.             {
  24.                 std::cout << "new width: " << event.size.width << std::endl;
  25.                 std::cout << "new height: " << event.size.height << std::endl;
  26.             }
  27.             else if (event.type == sf::Event::MouseMoved)
  28.             {
  29.                 cout << "New width of cursor: " << event.mouseMove.x<< endl;
  30.                 cout << "New height of cursor: " << event.mouseMove.y << endl;
  31.             }
  32.         }
  33.     }
  34.  
  35.     int pause; cin >> pause; //Pause the program
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement