This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hello !

I need some help about weird lines appearing above sprites. I can't figure out what they are or what I need to do to remove them.

My scene consists of sprites (12px/10px) arranged in an hexagonal grid like that (with debug lines) :

hex grid

Really rarely when I move the camera and zoom weird lines appear, here an horizontal line :

lines

Script attached to the camera :

extends Camera2D

const MAX_ZOOM_LEVEL = 0.25
const MIN_ZOOM_LEVEL = 2.0
const ZOOM_PERCENT = 0.02

signal moved()
signal zoomed()

var _current_zoom_level = 1
var _drag = false

func _input(event):
    if event.is_action_pressed("cam_drag"):
        _drag = true
    elif event.is_action_released("cam_drag"):
        _drag = false
    elif event.is_action("cam_zoom_in"):
        _update_zoom(1-ZOOM_PERCENT, get_local_mouse_position())
    elif event.is_action("cam_zoom_out"):
        _update_zoom(1+ZOOM_PERCENT, get_local_mouse_position())
    elif event is InputEventMouseMotion && _drag:
        set_offset(get_offset() - event.relative * _current_zoom_level)
        emit_signal("moved")

func _update_zoom(percent, zoom_anchor):
    var old_zoom = _current_zoom_level
    _current_zoom_level *= percent
    if _current_zoom_level < MAX_ZOOM_LEVEL:
        _current_zoom_level = MAX_ZOOM_LEVEL
    elif _current_zoom_level > MIN_ZOOM_LEVEL:
        _current_zoom_level = MIN_ZOOM_LEVEL
    if old_zoom == _current_zoom_level:
        return
    var zoom_center = zoom_anchor - get_offset()
    var ratio = 1-_current_zoom_level/old_zoom
    set_offset(get_offset() + zoom_center*ratio) 
    set_zoom(Vector2(_current_zoom_level, _current_zoom_level))
    emit_signal("zoomed")

Stretch settings are 2d Mode and ignore Aspect.
I use default settings when importing my sprites (expect removing filtering).

So where do these lines come from ? I've tried using bigger sprites (48px/40px) and lines aren't appearing.
Is it linked to pixel-perfect stuff or settings when importing sprites ?

I would really appreciate if someone can figure it out. :)

in Engine by (62 points)

Zoom values aren't integer values, since 2x zoom corresponds to set_zoom(Vector2(0.5, 0.5)) on my camera.

Yes but have you tried integer values to see if the lines still appear?

Lines appear even with zoom Vector(2, 2)

I'm out of ideas I'm afraid. Hopefully someone will chip in and help you figure this out :)

No problem, thanks a lot. <3

2 Answers

0 votes

I have the same exact issue with my isometric pixelated tiles. A very simple fix that I found was to increase the scale of the tiles by 0.001. Not the perfect fix but so far it seems to get rid of the lines without disturbing the conformity of the tiles themselves.

I know this is an old post but I figured I'd share my findings anyway.

by (21 points)
+1 vote

I recently encountered this same issue and the other answer provided here wasn't sufficient to resolve it (Godot 3.0.5). I found another workaround and have a potential explanation.

The root cause of this issue appears to be an interaction between texture flags 1 (FLAGMIPMAPS) and 2 (FLAGREPEAT) combined with a scaled object (in my test case, a sprite).

To fix the issue, set the sprite.texture.flags property to remove either of these flags (I recommend either 5 or 6 as the default is 7). For example: get_node("Sprite").texture.flags = 5
or
get_node("Sprite").texture.flags = Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER

by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.