2016-10-26 4 views

ответ

0

Там нет shape.makeClickable() функции SFML, все, что вам нужно сделать, это:

sf::CircleShape* onClick(float mouseX, float mouseY) {//Called each time the players clicks 
    for (sf::CircleShape& circle : vec) { 
     float distance = hypot((mouseX - circle.getPosition().x), (mouseY - circle.getPosition().y)); //Checks the distance between the mouse and each circle's center 
     if (distance <= circle.getRadius()) 
      return &circle; 
    } 
    return nullptr; 
} 

С помощью этого вектора в классе:

std::vector<sf::CircleShape> vec; 

EDIT
Чтобы получить все круги, которые вы кликнули -он, а не только первый, который он находит:

std::vector<sf::CircleShape*> onClick(float mouseX, float mouseY) {//Called each time the players clicks 
    std::vector<sf::CircleShape*> clicked; 
    for (sf::CircleShape& circle : vec) { 
     float distance = hypot((mouseX - circle.getPosition().x), (mouseY - circle.getPosition().y)); //Checks the distance between the mouse and each circle's center 
     if (distance <= circle.getRadius()) 
      clicked.push_back(&circle); 
    } 
    return clicked; 
} 
Смежные вопросы