Changing the sprite of a node instance

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

I’m making a snake game, and I’m trying to figure out the best way to change the sprite of the last part of the snake.

func add_part():
   var new_part = bodyPart.instance()
   new_part.global_position = segments[-1].global_position
   segments.append(new_part)
   add_child(new_part)

segments[-1] gives me the instance I want to change the sprite of,
I thought doing new_part.Sprite would work but it doesn’t.

And bodyPart is just a Node2D with a Sprite child.

:bust_in_silhouette: Reply From: Regulus

You can usenew_part.get_node("Sprite") to get the child Sprite.