Scaling issue in 2D

Godot Version

4.4.1

Question

I am using a Node2D to represent the backgound of my “level”. Inside i have placed a Camera2D to manage pan & zoom in the level.

On the level i place both Sprite2Ds (manually instantiated by script, since items are generate outside) that i manually place on the level with:

position = Vector2( item_x, item_y )

At the side of this, i also draw some lines and circles in the _draw methods of the sprite scenes, like:

(Sprite-derived scene, manually added above, this can be sprite_1 or sprite_2 below)
func _draw():
	if camera_zoom.x < 0.04:
		draw_circle( position, 5 / camera_zoom.x, Color.BLACK, true )

i also draw some lines within the level _draw method itself like:

(level scene, the background where the sprites have been added)
func _draw():
    var from: Vector2 = sprite_1.position
    var to: Vector2 = sprite_2.position
    draw_line( from, to, Color.GREEN )

The green line is properly drawn between the two Sprites, while the two circles are drawn displaced radially from the center of the level, the further the sprite is, the more displaced the circle is…

Am i missing something here?

I didn’t understand it fully, but if you call this _draw() function on a sprite2D and if you need the centre of the circle same as the position of the sprite, I think you should use Vector2.ZERO instead of position. Because _draw() uses local coordinates.
So, try this instead:

draw_circle(Vector2.ZERO, 5 / camera_zoom.x, Color.BLACK, true)

Of course!
it make totally sense… and of course, that’s the issue.

thank you.

1 Like