0 votes

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: drawprimitive: Drawing is only allowed inside NOTIFICATIONDRAW, 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

in Engine by (15 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.