Advertisement
Guest User

Untitled

a guest
Aug 21st, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/Window.hpp>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. //Render window
  8. sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Open GL Window", sf::Style::Default);
  9. //Limit frame rate
  10. window.setVerticalSyncEnabled(true);
  11. //Declares the texture
  12. sf::Texture texture1;
  13. //Loads the image
  14. if(!texture1.loadFromFile("figure.jpg"))
  15. {
  16. return 1;
  17. }
  18.  
  19. sf::Texture texture2;
  20.  
  21. if(!texture2.loadFromFile("background.jpg"))
  22. {
  23. return 1;
  24. }
  25.  
  26. //Loads the texture into the sprite
  27. sf::Sprite character(texture1);
  28.  
  29. sf::Sprite background(texture2);
  30.  
  31. //Main loop
  32. while (window.isOpen())
  33. {
  34. //Declaration for event
  35. sf::Event event;
  36.  
  37. while(window.pollEvent(event))
  38. {
  39. if (event.type == sf::Event::Closed)
  40. {
  41. window.close();
  42. }
  43.  
  44. if (event.type == sf::Event::Resized)
  45. {
  46. sf::Event::Resized;
  47. }
  48.  
  49. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  50. {
  51. character.move(-10, 0);
  52. }
  53.  
  54. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  55. {
  56. character.move(10, 0);
  57. }
  58.  
  59. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  60. {
  61. character.move(0, -10);
  62. }
  63.  
  64. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  65. {
  66. character.move(0, 10);
  67. }
  68. }
  69. window.clear();
  70.  
  71. window.draw(background);
  72.  
  73. window.draw(character);
  74.  
  75. window.display();
  76. }
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement