c++ - How to get reference to clicked sf::CircleShape? -
in sfml program storing drawn circleshapes in vector. how reference 1 on clicking mouse button?
there's no shape.makeclickable()
function in sfml, have is:
sf::circleshape* onclick(float mousex, float mousey) {//called each time players clicks (sf::circleshape& circle : vec) { float distance = hypot((mousex - circle.getposition().x), (mousey - circle.getposition().y)); //checks distance between mouse , each circle's center if (distance <= circle.getradius()) return &circle; } return nullptr; }
with vector in class:
std::vector<sf::circleshape> vec;
edit
circles have clicked-on, , not first 1 finds :
std::vector<sf::circleshape*> onclick(float mousex, float mousey) {//called each time players clicks std::vector<sf::circleshape*> clicked; (sf::circleshape& circle : vec) { float distance = hypot((mousex - circle.getposition().x), (mousey - circle.getposition().y)); //checks distance between mouse , each circle's center if (distance <= circle.getradius()) clicked.push_back(&circle); } return clicked; }
Comments
Post a Comment