Hello, I'm kinda new to SFML. I started with handling mouse inputs today and found this little problem:
When you click the left button on your mouse, hello will be drawn centrally to your mouse position. But if you maximze the window and click somewhere again hello is not central to your mouse position. Width seems to be central. Just the height between mouse and hello has changed.
Can someone explain this please?
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <time.h>
#include <sstream>
using namespace std;
using namespace sf;
int main()
{
VideoMode videoMode(1024,768);
RenderWindow window(videoMode,"Handling Mouse Input");
Font font;
if (!font.loadFromFile("Fonts/comic.ttf"))
return EXIT_FAILURE;
Text title("Handling Mouse Input",font,48);
FloatRect rect = title.getGlobalBounds();
title.setPosition((1024-rect.width)/2,10);
title.setColor(Color::Blue);
Text hello("HELLO",font,24);
FloatRect rect2 = hello.getGlobalBounds();
hello.setColor(Color::Red);
bool clicked=false;
while(window.isOpen())
{
window.clear();
window.draw(title);
if(clicked)
{
window.draw(hello);
}
window.display();
if(Mouse::isButtonPressed(Mouse::Left))
{
Vector2i mouse = Mouse::getPosition();
hello.setPosition(mouse.x-(rect2.width/2),mouse.y-(rect2.height*2));
clicked=true;
}
Event event;
while(window.pollEvent(event))
{
if( (event.type == Event::Closed) ||
((event.type == Event::KeyPressed) && (event.key.code==Keyboard::Escape)) )
window.close();
}
}
return EXIT_SUCCESS;
}