Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mouse Click without isButtonPressed  (Read 1718 times)

0 Members and 1 Guest are viewing this topic.

JeromeBaur

  • Newbie
  • *
  • Posts: 2
    • View Profile
Mouse Click without isButtonPressed
« on: October 25, 2011, 06:44:34 pm »
Hey

I tryed first to simulate a click on a button and i used:

Code: [Select]
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 =)

unranked86

  • Newbie
  • *
  • Posts: 37
    • View Profile
Mouse Click without isButtonPressed
« Reply #1 on: October 26, 2011, 12:06:17 am »
Maybe I got it wrong, what you want to achieve, but check out the ConvertCoords function.
Possible usage might be something like this:

Code: [Select]

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
}
//...