![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | newbie09 |
I have autoloaded Engine.tscn as engine
Engine.gd attached to Engine.tscn
extends Node2D
func polygon(center:Vector2, points, radius, rotation, outline:bool, thick, color:Color, alpha):
print_debug("drawing polygon")
var c : PoolColorArray
var p : PoolVector2Array
var pp : PoolVector2Array
var cc : PoolColorArray
var x
var y
var ang = 360/points
color.a = alpha
if not outline:
thick = radius
for i in range(points+1):
x = cos(deg2rad(ang*(i%points)+rotation))*radius + center.x
y = sin(deg2rad(ang*(i%points)+rotation))*radius + center.y
c.append(color)
p.append(Vector2(x,y))
if i > 0:
draw_primitive(p, c, p, null, 1, null)
c.remove(0)
p.remove(0)
x = cos(deg2rad(ang*(i%points)+rotation))*(radius-thick) + center.x
y = sin(deg2rad(ang*(i%points)+rotation))*(radius-thick) + center.y
c.append(color)
p.append(Vector2(x,y))
if i > 0:
draw_primitive(p, c, p, null, 1, null)
c.remove(0)
p.remove(0)
Main.gd attached to Main.tscn
extends Node2D
var runtime = 0
func _ready():
pass
func _process(delta):
runtime += delta
update()
func _draw():
engine.polygon(
OS.get_real_window_size()/2,
3, 50, runtime*100, true, 25, Color.cyan, 1)
but nothing draw.
ERROR: draw_primitive: Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or ‘draw’ signal.
At: scene/2d/canvas_item.cpp:866.
I’m totally new to Godot and can’t really find a solution
is there anyway I can create a draw function that can call globally cause this polygon is gonna be use a lot in my project