2016-10-26 6 views

答えて

0

SFMLにはshape.makeClickable()機能はありません、あなたがしなければならないすべては、次のとおりです。あなたがクリックしたALL円を得るために

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

EDIT
:あなたのクラスでこのベクターで

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*> 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; 
} 
関連する問題