Modify sprites of an instance

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

I have an enemy that is a rigid body, and has a sprite as a child.

I can modify its speed and rotation after instantiating it, but I cannot modify the sprite

var mob = Mob.instance()
add_child(mob)
mob.rotation = direction
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)     
mob.linear_velocity = mob.linear_velocity.rotated(direction)

try this way but it returns an error

mob/Sprite.texture = load("res://Img/yellow.png")

What error do you get, specifically.

jgodfrey | 2020-11-22 20:55

Parser Error: Can’t assign to an expression

Yamz | 2020-11-22 20:56

:bust_in_silhouette: Reply From: jgodfrey

That needs to be:

mob.get_node("Sprite").texture = ...

Thank you very much, it works perfect

Yamz | 2020-11-22 21:09

Sorry for the inconvenience but I could open a way to call it from a Singleton (AutoLoad)

Yamz | 2020-11-22 21:19

Mmmm… I really don’t understand what you’re asking here… Call what from a singleton?

jgodfrey | 2020-11-22 22:35