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

Popular posts from this blog

c++ - CPP, 'X' button listener -

shared memory - gstreamer shmsrc and shmsink with h264 data -

.net - Bulk insert via Dapper is slower than inserting rows one-by-one -