- Edited
Hey Community.
I am new here and actually struggeling rly hard on this kind of topic.
I just wanted to build a draw tool, where the background is transparent and I easily can draw above it and erase again. The background should be untouched. My first mention were to actually just take the same colour as the background and overwrite the lines. This would be actually an ugly working way, when I don't want to have the Rectangle transparant with modulate alpha.
The second way I tried to just remove the points where I moved over it with the mouse. This actualy quiet don't work, because (how I understood it) the draw function itself still connect the lines between the left points. So I get something like this:
The endresult of the painting tool should look like this with a transparent untouched background (background is missing, because I dont get it work. I mean the draw and erase part.):
So in summary:
Solutions are actually:
- I see the background and the lines are also transparent.
- I see the background and lines are weird deleted.
- I see no background and the lines are like they should.
I am open for any other solution, for example I have read smth with shaders and viewport, but isnt there the same issue with the alpha channel?.
Code:
extends Node2D
@onready var _lines := $Draw_Container/Lines
var _pressed := false
var _current_line: Line2D
#var actual_color = Color.WHITE
var actual_color
var drawable = true
func _ready():
#$ColorRect.modulate.a = 0.7
actual_color = Color.WHITE
#actual_color.modulate.a = 0.7
get_node("Background_Filter").modulate.a = 1.0
get_viewport().get_window().current_screen = 1
func change_line_color(change_color_par):
actual_color = change_color_par
func _input(event) -> void:
if event.is_action_pressed("end_game"):
get_tree().quit()
if event.is_action_pressed("Interaction"):
#var color_eraser = Color(85, 85, 85, 1)
#print(color_eraser)
#change_line_color(color_eraser)
if actual_color == Color.WHITE:
change_line_color($Draw_Container/ColorRect.color)
elif actual_color == $Draw_Container/ColorRect.color:
change_line_color(Color.WHITE)
if event.is_action_pressed("clear_all_tool"):
var all_lines_erase = _lines.get_children()
var all_lines_erase_count = _lines.get_child_count()
for i in all_lines_erase_count:
all_lines_erase[i].queue_free()
if event.is_action_pressed("eraser_tool"):
if drawable:
drawable = false
elif !drawable:
drawable = true
#eraser_tool(event)
#draw
if drawable:
_lines.modulate.a = 1.0
print("draw modus")
if event is InputEventMouseButton:
_pressed = event.pressed
if _pressed:
_current_line = Line2D.new()
_current_line.default_color = actual_color
#_current_line.modulate.a = 0.5
_lines.add_child(_current_line)
if event is InputEventMouseMotion && _pressed:
_current_line.add_point(event.position)
#erase
if !drawable:
#print("eraser Modus")
if event is InputEventMouseButton:
print("hey")
var all_lines_erase =_lines.get_children()
var all_lines_erase_count = _lines.get_child_count()
for i in all_lines_erase_count:
var line_actual_point_count = all_lines_erase[i].get_point_count()
for j in line_actual_point_count:
var actual_point = all_lines_erase[i].get_point_position(j)
print("actual: ", actual_point.x, "\n", "mouse_pos: ",get_global_mouse_position().x)
if(actual_point.x > get_global_mouse_position().x):
print("actual: ", actual_point.x, "\n", "mouse_pos: ",get_global_mouse_position().x)
all_lines_erase[i].remove_point(j)
all_lines_erase[i].get_point_count()
Greetings Qusi