what is the best way to set the position of a node ?

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

What is the difference between:
$Node.position = Vector(a,b)

Both do the same don’t worry about it.
I like using Node.position but that is just a preference.

usurun | 2019-06-15 22:48

:bust_in_silhouette: Reply From: kidscancode

Note: your use of set_position() is incorrect - it takes a single argument of a Vector2, not two arguments.

Using the position property is preferred. Properties will be suggested by autocomplete. set_ and get_ functions were used in Godot pre-3.0 - and still exist for compatibility - but they just make your code more verbose. Compare:

$Node2D.set_position($Node2D.get_position() + Vector2(100, 0))


$Node2D.position += Vector2(100, 0)
1 Like