Path2d / "close curve" with code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ramazan

Is there a way to “close curve” with code?

                              =====>
   start ==> ########################################
                                                    #    
                                                    #
  finish ==> #                                      # 
             #                                      ######
             #                                           #   
             #                                           #
             #############################################  
                              <=====
:bust_in_silhouette: Reply From: sash-rc

Basically you should assign coordinates of a first point to the last point of underlying curve


func close_path(path : Path2D) -> void:
    var curve : Curve2D = path.curve
    var cnt = curve.get_point_count()
    if cnt :
        curve.set_point_position( cnt-1, curve.get_point_position(0) )
# not tested

thank you very much. path merges when I run the path function twice, but I don’t know why :slight_smile: . I also don’t like using code that I don’t know.

ramazan | 2022-07-27 22:11