Advertisement
Guest User

SFML Project 2nd Iter

a guest
Aug 12th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include "SFML Files\include\SFML\Window.hpp"
  4. #include "SFML Files\include\SFML\Graphics.hpp"
  5.  
  6. int main()
  7. {
  8. sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
  9.  
  10. sf::Texture texture;
  11. texture.loadFromFile("tile1.png");
  12.  
  13. sf::Sprite sprite;
  14. sprite.setTexture(texture);
  15. sprite.setPosition(100, 100);
  16.  
  17. sf::FloatRect tileRect(100.0f, 100.0f, 48.0f, 48.0f);
  18.  
  19. sf::Vector2f relativePosition = window.mapPixelToCoords(sf::Mouse::getPosition(window));
  20.  
  21. // run the program as long as the window is open
  22. while (window.isOpen())
  23. {
  24. // check all the window's events that were triggered since the last iteration of the loop
  25. sf::Event event;
  26. while (window.pollEvent(event))
  27. {
  28. // "close requested" event: we close the window
  29. if (event.type == sf::Event::Closed)
  30. window.close();
  31. }
  32. window.clear();
  33.  
  34. if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  35. {
  36. if (tileRect.contains(relativePosition))
  37. {
  38. std::cout << "THEY INTERSECT" << std::endl;
  39. }
  40. else
  41. {
  42. std::cout << "NO INTERSECTION" << std::endl;
  43. }
  44.  
  45. std::cout << sf::Mouse::getPosition(window).x << std::endl;
  46. std::cout << sf::Mouse::getPosition(window).y << std::endl;
  47. }
  48.  
  49. window.draw(sprite);
  50. window.display();
  51. }
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement