-
kalifireLikes 0Problem DescriptionHey, I used your tutorial 51 for sfml on youtube to create menu for a game I am working on.In the video, you allowed user keyboard input to select play,options or exit with the keyboard.
void Menu::MouseClick(sf::RenderWindow &window)
{//sf::Mouse::setPosition(sf::Vector2i(0, 0));if (sf::Mouse::isButtonPressed(sf::Mouse::Left))&& sf::Mouse::getPosition().x == 0 && sf::Mouse::getPosition().y == 0)cout<<"Mouse is within bounds" <<endl;
{
}
}
I even got a (x,y) that was within my play button ex (240,113) is a coord that is close enough to the play button that I want the user to click. so if i use 240,113 in my getPosition for x,y values what I found out was that it only sets that single pixel not a wide area to click on for my play button which is what I want.
s.
sf::RectangleShape Rectangle;
//set size = to a size a bit bigger than the play button(height and width)
Rectangle.setSize(sf::Vector2f(62, 54));
//puts the rectangle over the play button
Rectangle.setPosition(250, 120); //hardcoded the position of Rectangle (x,y) 250,120 is the origin of the very left corner of the rectangle
-
Sonar Systems adminLikes 0
How much is the position off by?
-
kalifireLikes 0
well the problem is that the (240,113) coord sets to a single pixel on the screen, and so you have to click that specific pixel for the play button to run. Normally you can click anywhere on the “play” button for it to run not a specific pixel of play.
-
Sonar Systems adminLikes 0
My game engine https://github.com/SonarSystems/Flappy-Bird-SFML-Clone/tree/master/Code/GAME%20ENGINE%20SETUP/6%20-%20Input%20Manager
Has the feature you require in the InputManager file
-
kalifireLikes 0
Thank you, that fixed most of it for some reason only about half of the play button is registering a click.
-
Sonar Systems adminLikes 0
Show us the code.
-
kalifireLikes 0
if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && sf::Mouse::getPosition(window).x && sf::Mouse::getPosition(window).y)
{
sf::IntRect playButtonRect(menu[0].getPosition().x, menu[0].getPosition().y, menu[0].getGlobalBounds().width, menu[0].getGlobalBounds().height);if (playButtonRect.contains(sf::Mouse::getPosition(window)))
{
cout << "play button is clicked " << endl;
return true;
}
return false;
}
-
Sonar Systems adminLikes 0
Can you show us a video demonstration of the problem.
Login to reply