0 votes
extends Node2D

var tilesArray = []
var center = Vector2(300, 300)

func _ready():
    for i in range(0, 20):
        tilesArray.append([])
        for j in range(0, 20):
            var point = Vector2(i*50, j*50)
            var x = point.angle_to_point(center)/PI
            var rand_min = rand_range(0.35, 0.65)
            var rand_max = rand_range(0, 0.15)
            var r = max(min(-10*(x+11.0/12.0)*(x-7.0/12.0), rand_min), rand_max)
            var g = max(min(10*(x+9.0/12.0)*(x+3.0/12.0), rand_min), rand_max)
            var b = max(min(10*(x+1.0/12.0)*(x-5.0/12.0), rand_min), rand_max)
            tilesArray[i].append([r, g, b])

func _draw():
    for i in range(0, 20):
        for j in range(0, 20):
            draw_rect(Rect2(i*50, j*50, 50, 50), Color(tilesArray[i][j][0], tilesArray[i][j][1], tilesArray[i][j][2], 1))

I made this code sample to generate a small colored map.
Just running this on a Node2D works fine except for some small visual glitches :

Some of the rectangles disappear for a fraction of a second sporadically, even though I don't redraw.

Any idea why ?
Am I using _draw() wrong ?
What should I do ?

Thanks in advance for your help :)

asked Nov 26, 2019 in Engine by Sogeking (20 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 How to use this Q&A? before posting your first questions.