Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <SFML\System.hpp>
- #include "SFML Files\include\SFML\Window.hpp"
- #include "SFML Files\include\SFML\Graphics.hpp"
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
- sf::Texture texture;
- texture.loadFromFile("tile1.png");
- sf::Sprite sprite;
- sprite.setTexture(texture);
- sprite.setPosition(100, 100);
- sf::Mouse mouse;
- sf::Rect<float> mouseRect;
- mouseRect.width = 1.0f;
- mouseRect.height = 1.0f;
- sf::Rect<float> tileRect;
- tileRect.left = 100.0f;
- tileRect.width = 48.0f;
- tileRect.top = 100.0f;
- tileRect.height = 48.0f;
- // run the program as long as the window is open
- while (window.isOpen())
- {
- // check all the window's events that were triggered since the last iteration of the loop
- sf::Event event;
- while (window.pollEvent(event))
- {
- // "close requested" event: we close the window
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear();
- mouseRect.left = mouse.getPosition(window).x;
- mouseRect.top = mouse.getPosition(window).y;
- if (mouse.isButtonPressed(mouse.Left))
- {
- if (mouseRect.intersects(tileRect))
- {
- std::cout << "THEY INTERSECT" << std::endl;
- }
- else
- {
- std::cout << "NO INTERSECTION" << std::endl;
- }
- std::cout << mouseRect.left << ", " << mouseRect.top << std::endl;
- }
- window.draw(sprite);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement