Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The way camera:attach is implemented makes supporting non-even dimension difficult #64

Closed
bitinn opened this issue Apr 25, 2016 · 7 comments

Comments

@bitinn
Copy link

bitinn commented Apr 25, 2016

Most of the discussion is here: karai17/Simple-Tiled-Implementation#106

In short, given current implementation, we will always get non-integer translation when attaching camera on a game window with odd number as dimensions, and there is nothing we can do except to give gap between tiles (not really a great solution when you have hundreds of tilesets without margins)

https://github.com/vrld/hump/blob/master/camera.lua#L105-L112

@bitinn
Copy link
Author

bitinn commented Apr 25, 2016

I actually prefer the way gamera work, which leaves us a way to avoid float number translation.

https://github.com/kikito/gamera/blob/master/gamera.lua#L100-L106
https://github.com/kikito/gamera/blob/master/gamera.lua#L179-L181

@vrld
Copy link
Owner

vrld commented Apr 26, 2016

The problem is that hump.camera translates to a fractional position, which causes artifacts between the tiles, correct?
Rounding the position to the nearest integer by default would work, but introduces two other issues:

  1. It does only work for scale = 1, and
  2. Moving the camera becomes jittery.

A quick and dirty solution would add a parameter to camera:attach() to transform the calculated screen center, e.g. camera:attach(math.floor) - but I am not yet sure how I feel about that.

The "correct" way would be to add margins in the tile set, but as you said, that might not be practical.
Another solution might be to try the FilterMode 'nearest'.

@bitinn
Copy link
Author

bitinn commented Apr 26, 2016

Another solution might be to try the FilterMode 'nearest'.

As far as I know STI uses nearest when loading tileset, but that doesn't seem to help. Which puzzles me.

@vrld
Copy link
Owner

vrld commented May 1, 2016

Can you provide a .love that shows the issue so that I can have a look myself?

@bitinn
Copy link
Author

bitinn commented May 1, 2016

Actually let me close this for now, I needed a visible viewport anyway so I switched to gamera.

I don't think it's that necessary for hump.camera to support my use-case, while my project do fit into your 2 conditions (we don't scale map, we don't need smooth camera movement), I think it complicates your code quite a bit to support strict non-float position, so yeah if I ran into the issue again I will re-open this with an example .love file.

@bitinn bitinn closed this as completed May 1, 2016
@vrld
Copy link
Owner

vrld commented May 1, 2016

Reopening this: defining a custom viewport when attaching the camera is straightforward to implement and should cover your use-case. Something along the lines of this:

cam:attach(20, 10, 400, 400) -- x,y,width,height
foo()
cam:detach()

@vrld vrld reopened this May 1, 2016
@vrld vrld closed this as completed in 40f0820 May 1, 2016
@bitinn
Copy link
Author

bitinn commented May 1, 2016

very cool, I will check it out when available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants