G
G
Gotenks2019-01-20 18:52:54
C++ / C#
Gotenks, 2019-01-20 18:52:54

How to check clicks inside an area?

The code
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <Windows.h>


void SA()
{
  sf::RenderWindow SA(sf::VideoMode(1920, 1080), "ПИРИВАДЧИК!!!");
  
  sf::Texture stroka;
  stroka.loadFromFile("stroka");
  sf::Sprite strokaS;
  strokaS.setTexture(stroka);
  
  sf::Font strokaF;
  strokaF.loadFromFile("CyrilicOld.tff");
  bool checkPosition1 = false;
  bool checkPosition2 = false;
  sf::IntRect area1(132, 322, 887 - 132, 920 - 322);
  sf::IntRect area2(1032, 308, 1785 - 1032, 907 - 308);
  sf::Vector2i i;
  while (SA.isOpen())
  {
    sf::Event event;
    while (SA.pollEvent(event))
    {
      switch (event.type)
      {
      case sf::Event::Closed:
        SA.close();
          break;
      case sf::Keyboard::Key::Escape:
        SA.close();
        break;
      case sf::Event::MouseMoved:
        i = sf::Mouse::getPosition(SA);
        
      }
    }
  }
}

How to check for a mouse click inside an area specified in an IntRect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vigiv, 2019-01-26
@Gotenks

sf::IntRect rect;
if (rect.contains(sf::Mouse::getPosition(window)))
{

}

If you need the mouse coordinates in the window, then pass it to sf::Mouse::getPosition as the window parameter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question