Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #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::FloatRect tileRect(100.0f, 100.0f, 48.0f, 48.0f);
- sf::Vector2f relativePosition = window.mapPixelToCoords(sf::Mouse::getPosition(window));
- // 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();
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- if (tileRect.contains(relativePosition))
- {
- std::cout << "THEY INTERSECT" << std::endl;
- }
- else
- {
- std::cout << "NO INTERSECTION" << std::endl;
- }
- std::cout << sf::Mouse::getPosition(window).x << std::endl;
- std::cout << sf::Mouse::getPosition(window).y << std::endl;
- }
- window.draw(sprite);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement