0 votes

Hello everyone,
I am doing project where I mimic drawing of lines through strokes of a a brush. The brush is a KinematicBody2D which has a trailing line behind it. The line is formed by a $Line by adding points as the brush moves and mimics providing strokes. The brush's moves is restricted by walls which are made up of StaticBody2Ds.

Here is the Scene structure:

https://drive.google.com/file/d/1w7aoGGGJbStMnAoHp_VgybDgexSENRB2/view?usp=sharing

extends KinematicBody2D

onready var line = get_node("../line")
var speed = 250
var velocity = Vector2(0,0)
var use_slide = true
var adjust =Vector2(10, 0)
var old_position
var carry_on = true
var strokes = 100



func get_input():
    velocity = Vector2()
    old_position = position
    if Input.is_action_pressed('ui_right'):
        velocity.x += 1
    if Input.is_action_pressed('ui_left'):
        velocity.x -= 1
    if Input.is_action_pressed('ui_down'):
        velocity.y += 1
    if Input.is_action_pressed('ui_up'):
        velocity.y -= 1
    velocity = velocity.normalized() * speed

func _physics_process(delta):
    get_input()
    var temp = get_viewport().get_mouse_position()
    move_and_slide(velocity)
    line.add_point(old_position)
    line.add_point(position)

The problem is that although the lines do get traced as I move the KinematicBody2D, they all disappear together after a finite lapse of time. After the lines disappear, the lines do not get traced anymore even after I move the brush (read, KinematicBody2D).

What am I doing wrong? How can I make the traced lines to remain persistent?

Please help.

Godot version 3.2.2
in Engine by (100 points)
edited by

Access denied on that link.

Sorry about that.
Have updated the access criteria.
Thanks for pointing that out.

I had missed out a few variables and a few lines of code. Have updated the code also.
Thanks in advance.

Do you get any errors in Godot?

1 Answer

+1 vote
Best answer

You have too many points in your Line2D! As stated in the docs here,

By default, Godot can only draw up to 4,096 polygon points at a time.

Try only adding points when velocity is not zero to reduce the number of points you draw.

by (7,769 points)
selected by

Thanks a lot. This works.

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.
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 webmaster@godotengine.org with your username.