system
March 18, 2016, 2:23pm
1
system
March 18, 2016, 3:03pm
4
Reply From:
Bojidar Marinov
There are a few options you might do:
Move drawing to a child node, and change it’s Z-index.
Use VisualServer::canvas_item_create
and similar functions to create a non-existent (in the scene tree) canvas item, whose Z-index you might change.
Toggle Show Behind Parent
on those child instanced nodes…
Thank you. I totally forgot about the show behind parent option. This is already all I need.
PixelWizzard | 2016-03-18 15:07
Reply From:
boruok
here how can you draw with directy with VisualServer → Godot — рисование без правил / Хабр
extends Node2D
onready var drawer = $"../Drawer"
var counter = 0
func custom_draw_line(start, goal, color, width=1.0, antialising=false):
VisualServer.canvas_item_add_line(drawer.get_canvas_item(), start, goal, color, width, antialising)
func _process(delta):
if Input.is_action_just_pressed("mouse_left"):
counter += 2
custom_draw_line(Vector2(100, 100)+Vector2(counter, counter), Vector2(300, 150)+Vector2(counter, counter), Color.green)
another example:
extends Node2D
onready var drawer = $"../Drawer"
var counter = 0
var surface
func _ready():
surface = VisualServer.canvas_item_create()
VisualServer.canvas_item_set_parent(surface, drawer.get_canvas_item())
func custom_draw_line(start, goal, color, width=1.0, antialising=false):
VisualServer.canvas_item_add_line(surface, start, goal, color, width, antialising)
func _process(delta):
if Input.is_action_just_pressed("mouse_left"):
counter += 2
custom_draw_line(Vector2(100, 100)+Vector2(counter, counter), Vector2(300, 150)+Vector2(counter, counter), Color.green)
elif Input.is_action_just_pressed("mouse_right"):
VisualServer.canvas_item_clear(surface)
counter = 0