Hi, I am using SFML2.5.1 and Thor, and I am not able to get a getGlobalBounds().contains to have the mouse button click over a sprite, someone can tell me why :-( ?
THE OBJECTS THAT I TRIED
//RECTANGLE
//sf::RectangleShape closeButton;
//closeButton.setSize(sf::Vector2f(200.0f, 80.0f));
//closeButton.setPosition(300.0f, 260.0f);
//closeButton.setFillColor(sf::Color::Red);
A FLOAT RECT
sf::FloatRect area1(550,0, 50, 20);
THE SAMPLE ROUNDEDRECT FROM THOR LIB
sf::ConvexShape roundedRect = thor::Shapes::roundedRect(sf::Vector2f(200.f, 100.f), 30.f, sf::Color(200, 190, 120), 3.f, sf::Color(150, 140, 80));
if (event.type == sf::Event::MouseButtonPressed )
{
if (event.mouseButton.button == sf::Mouse::Left) {
//THIS IS NOT WORKING Thats is the supposed way to operate but is not working for me
//if (closeButton.getGlobalBounds().contains(window.mapPixelToCoords(sf::Vector2i(event.mouseButton.x, event.mouseButton.y)))) {
//THIS WORK but is not precise, is not using the shape surface
//if ( sf::Mouse::getPosition(window).x > 550 && sf::Mouse::getPosition(window).y < 20 ) {
// Mouse is inside the sprite.
std::cout << "Button pressed" << std::endl;
}
}
}
COMPILER ERRORS:
Error(active) E0864 Rect is not a model Shapes C:\Users\pc\Documents\Visual Studio 2017\Resources\SFML-2.5.1-win32\include\SFML\Graphics\Rect.inl 52
Errore (attivo) E0864 Vector2 is not a model Shapes C:\Users\pc\Documents\Visual Studio 2017\Resources\SFML-2.5.1-win32\include\SFML\Graphics\Rect.inl 52
Errore (attivo) E1670 qualificator not permitted in a non member function Shapes C:\Users\pc\Documents\Visual Studio 2017\Resources\SFML-2.5.1-win32\include\SFML\Graphics\Rect.inl 76
Thanks!
This user in that topic says:
//Ok, I'm getting 8 errors and I have no clue why...
//Here is the line of code that I've narrowed it down too:
if (exitRect.getGlobalBounds().contains(window.mapPixelToCoords(sf::Mouse::getPosition(window))))
I mean how do you reach / or how to arrive to that solution?
You most likely include (something that includes) <windows.h> before SFML headers. Several possible solutions:
- get rid of that include if you don't need it
- define the preprocessor symbol NOMINMAX in your project settings
- #undef "min" and "max" symbols immediatly after including windows.h
- do not include any SFML header after windows.h, if possible
solution #2 is the cleanest (or #1 if you have windows.h included just for fun).
It's that based on your experience like damning the screen, or invoke mistic creatures, cursing the lamp etc ?