Change animation sprite from one scene

i want to make gallery

do i have to make to another scene or there is some way command script to change animation when click?

sorry if my english was broken

if you want to change the animations you can do that by using code like :

extends Node2D


func _on_play_front_pressed() -> void:
	$AnimatedSprite2D.play("front")


func _on_play_back_pressed() -> void:
	$AnimatedSprite2D.play("back")

can you explain a bit more what you want?

i want to make gallery just as example above but i click on menu scene go to animation scene.

so if use code above it works on only one scene that’s why i use get_tree().change_scene_to_file()

Its better if you use the inherent property’s of AnimatedSprite2D

if you reference your AnimatedSprite2D

extends Node #this script would be the main script for the scene

@export var cow: AnimatedSprite2D 
#also you can right click a Node and click 'Access as Unique Name' then access it using %AnimatedSprite2D 
#or whatever the node is named (if you renamed the node cow then access it using %cow)

_on_front_button_pressed() -> void:
cow.animation = &"front"

_on_back_button_pressed() -> void:
cow.animation = &"back"

If you want to have multiple instances like in your fourth picture I would create a second AnimatedSprite2D in the same scene and access it using another export like:

@export var cow: AnimatedSprite2D
@export var cow2: AnimatedSprtie2D

or do ‘Access as Unique Name’ like before (right click the node, then select the ‘Access as Unique Name’ option) (i recommend to change the nodes names to something like cow_front and cow_back)

%cow_front.animation = &"front"
%cow_back.animation = &"back"
1 Like