Thursday, April 19, 2018

21. draw_line

We use a root Node2D and attach a script.


In the script, we draw 3 lines using draw_line function of CanvasItem which is in the Node2D hierarchy. We have to use the virutal function _draw() from this class.


This script is attached to the Node2D.



extends Node2D

var from = Vector2(10,10)
var to = Vector2(190,20)
var col = Color(0,0,1)

func _draw():
    draw_line (from, to, col)
    from += Vector2(0, 50)
    to += Vector2(0, 50)
    draw_line (from, to, col, 5)
    from += Vector2(0, 50)
    to += Vector2(0,50)
    draw_line (from, to, col, 5, true)


This is the output showing the 3 lines (first line has width of 1 while second and third line have width of 5).

No comments:

Post a Comment