Julian-Vos / asset-library-MapCamera2D-4

https://github.com/Julian-Vos/godot-scripts/tree/master
MIT License
10 stars 2 forks source link

Zoom artifacts #5

Open empireoftheclouds opened 1 week ago

empireoftheclouds commented 1 week ago

I noticed that with this script active zoom artifacts happen, even when the zoom factor is set to 2.0 (min 1.0 - max: 10.0, so soom level: 1x, 2x, 4x, 8x, 10x). Artifacts The artifacts happen on the corners of the sprites, and in my project I use a hexagonal TileMapLayer so this issue is extremely noticable. But it doesn't happen always and not on the same zoom level. I removed most of the camera code and with this minimal zoom script

extends Camera2D

@export var zoom_factor: float = 2.0

func _unhandled_input(event):
    if event is InputEventMouseButton:
        if event.pressed:
            match event.button_index:
                MOUSE_BUTTON_WHEEL_UP:
                    zoom *= zoom_factor
                    zoom.x = clampf(zoom.x, 1.0, 10.0)
                    zoom.y = clampf(zoom.y, 1.0, 10.0)
                MOUSE_BUTTON_WHEEL_DOWN:
                    zoom *= (1 / zoom_factor)
                    zoom.x = clampf(zoom.x, 1.0, 10.0)
                    zoom.y = clampf(zoom.y, 1.0, 10.0)

    print("zoom: ", zoom)

it does not happen. I created a minimal reproduction project, but it happend just like it did in my main project, so I assume that this script causes this. Weirdly, I even print the zoom factor and it has no decimal places which could be the issue. Here is the MRP: camera_zoom_bug.zip if you attach the MapCamera2D.gd script to the Camera2D node and zoom in and out (it may take a few times) at some point the artifacts will occur. Then attach the camera_minimal.gd to the Camera2D node and to the same thing and it will not happen. In my project I use a hexagonal tilemap, and the artifacts occur on the edges / corners, so I added one to the MRP.

Julian-Vos commented 3 days ago

Hello, thank you for the report and the minimal reproduction project! I only see the seams when the zoom level becomes fractional, which can still happen when zooming by touchpad (InputEventMagnifyGesture and InputEventPanGesture). It happens in the editor too, and unfortunately I wasn't able to fix it through filter, import or project settings. I think the problem is that your hex sprite is slightly smaller than the TileMapLayer's hexagon at some places:

Screenshot 2024-10-11 at 10 54 25