Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(700, 700), "sfml work", sf::Style::None | sf::Style::Close);
- sf::View vue;
- sf::RectangleShape shape(sf::Vector2f(150, 150));
- sf::Event eventSF;
- shape.setFillColor(sf::Color::Blue);
- shape.setPosition(350, 350);
- while (window.isOpen())
- {
- while (window.pollEvent(eventSF))
- {
- if (eventSF.type == sf::Event::Closed)
- {
- window.close();
- //exit(0);
- }
- if (eventSF.type == sf::Event::MouseButtonPressed)
- {
- if (shape.getGlobalBounds().contains(sf::Vector2f(sf::Mouse::getPosition(window))))
- {
- std::cout << "Contain\n";
- }
- else
- {
- std::cout << "non\n";
- std::cout << sf::Mouse::getPosition(window).x << " // " << sf::Mouse::getPosition(window).y << "\n";
- std::cout << shape.getGlobalBounds().getPosition().x << " // " << shape.getGlobalBounds().getPosition().y << "\n";
- std::cout << shape.getPosition().x << " // " << shape.getPosition().y << "\n";
- }
- }
- }
- window.clear();
- window.setView(vue);
- window.draw(shape);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement