ryanisaacg / quicksilver

A simple framework for 2D games on desktop and web
https://ryanisaacg.github.io/quicksilver
Other
782 stars 77 forks source link

Graphics screen_to_camera doesn't take translation into account #647

Closed saw79 closed 4 years ago

saw79 commented 4 years ago

Title pretty much says it all I think. Looking at the source, it seems like the screen_to_camera function is based off the calculate_viewport function, which in theory is fine: it subtracts off the viewport's topleft coordinate. However the calculate viewport function always returns a Rectangle that is solely a function of its size - its top left is always something like size/2:

line 516: Rectangle::new((window.size() - size) / 2.0, size)

I think either the calculate_viewport function needs to return the camera translation or a different "viewport" like object needs to be used?

ryanisaacg commented 4 years ago

Can you post what you're seeing that's breaking as a result? I'm having trouble figuring out the problem from your report.

saw79 commented 4 years ago

So it's possible I'm just misunderstanding how to use the library. But I maintain a camera Rectangle that I use to pan/zoom around the world. I update my view with gfx.set_view.

Most of my input is the user clicking around the world with the mouse. So I use gfx.screen_to_camera, but it always returns the coordinates relative to the screen no matter where the camera position is. I'll translate the view around as much as I want, but gfx.screen_to_camera always returns (0, 0) for example if I'm always clicking in the top left. In fact, I don't think screen_to_camera does anything at all when there is no scale change.

Thanks for being so active and responsive, I think this library is great!

ryanisaacg commented 4 years ago

Oh! Yes, the screen_to_camera function should 100% take into account the current view. Thanks for the report.

ryanisaacg commented 4 years ago

Can you check out #648 and see if it fixes your issue?

saw79 commented 4 years ago

Cool I think it works!