SFML community forums
Help => Window => Topic started by: JeromeBaur on October 25, 2011, 06:44:34 pm
-
Hey
I tryed first to simulate a click on a button and i used:
if(sf::Mouse::IsButtonPressed(sf::Mouse::Left))
I don't know, probably it's a click but the programm don't reacte on the click sometimes and i have to click 5-10 times and press doesn't work everytime.
How can i solve this? I checked and the mouse(in the code) is on the button.
I hope you can help me =)
-
Maybe I got it wrong, what you want to achieve, but check out the ConvertCoords (http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderTarget.php#a49ef77424d1288d359850d160e099d3d) function.
Possible usage might be something like this:
sf::RenderWindow win(...);
//...
sf::FloatRect SomeRect; // you can get a rect from every sf::Text and sf::Sprite object, check the documentation, for more about this
sf::Vector2i mouse_pos = sf::Mouse::GetPosition(win);
if (sf::Mouse::IsButtonPressed(sf::Mouse::Left) && (SomeRect.Contains(win.ConvertCoords(mouse_pos.x, mouse_pos.y))))
{
// do something
}
//...