abraker95 / tanks

2D arcade top-view shooting game
1 stars 0 forks source link

UI mouse-button locations are mismatched when the window is resized #53

Closed ghost closed 9 years ago

ghost commented 9 years ago

https://github.com/Sherushe/tanks/issues/52

ghost commented 9 years ago

Idea: Create (or find if SFML has it) a function that translates mouse coordinates into coordinates relative to the size of the window.

ghost commented 9 years ago

Update: Doing that didn't help. Need ideas.

ghost commented 9 years ago

these function should work right? Their purpose is exactly converting window coordinates to world coordinates.

ghost commented 9 years ago

I tried using them, but it didnt work for some reason. The view stretching just doesnt get converted.

ghost commented 9 years ago

First the view has to be set (setView) and then you can use those functions.

getPosition and mapPixelToCoords use the current view.

I think it's just an usage problem.

ghost commented 9 years ago

The UI buttons isnt the only thing affected by it. The stats info (part of the HUD) also depends on view to screen coordinate conversion and suffers from the same bug.

ghost commented 9 years ago

I just figured out something. Have you tried this:

sf::Vector2i pixelPos = sf::Mouse::getPosition(_win);
sf::Vector2f worldPos = UIScene.mapPixelToCoords(pixelPos);

Maybe using the render target to convert the coordinates helps.

ghost commented 9 years ago

That's what I do to get the screen coordinate equivalent.

On Wed, Jan 14, 2015 at 5:28 PM, Sherushe notifications@github.com wrote:

I just figured out something. Have you tried this:

sf::Vector2i pixelPos = sf::Mouse::getPosition(_win); sf::Vector2f worldPos = UIScene.mapPixelToCoords(pixelPos);

Maybe using the render target to convert the coordinates helps.

— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/53#issuecomment-70005303.

ghost commented 9 years ago

Yeah, well, I just tested a couple of possibilities and this seems to work:

sf::Vector2i win_pos = sf::Mouse::getPosition(*_win);
Vec2f pos = _win->mapPixelToCoords(win_pos);

I guess it's normal because the render_target doesn't contain the window's size.

ghost commented 9 years ago

Ok I will check it out.

On Wed, Jan 14, 2015 at 7:12 PM, Sherushe notifications@github.com wrote:

Yeah, well, I just tested a couple of possibilities and this seems to work:

sf::Vector2i win_pos = sf::Mouse::getPosition(*_win); Vec2f pos = _win->mapPixelToCoords(win_pos);

I guess it's normal because the render_target doesn't contain the window's size.

— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/53#issuecomment-70018575.

ghost commented 9 years ago

Don't see mismatching anymore. This is pretty much solved.