Best way to play 2 single frames?

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

Hi, all! I was wondering if there was an efficient way to make a one-framed animation play at the beginning, and another after colliding with a kinematic body 2D (The animated sprite is on an Area2D)? I originally had both frames in their own animations, but neither of them worked. I then wondered if I should put them in one animation, and just have the animation run to switch the frame. Another thought was to have two completely different sprites, and destroy the unnecessary one after the collision.

So far, I’m testing working with one animation and two frames. None of the codes I’ve tried even changes the frame- it’s stuck on the first one. Here’s the code so far.

extends Area2D

export var connected = false

# Called when the node enters the scene tree for the first time.
func _ready():
	$AnimatedSprite.animation = "switch"
	$AnimatedSprite.set_frame(0)


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
	#pass

func _on_Area2D_body_entered(body):
	$AnimatedSprite.animation = "on"
	connected = true
	$AnimatedSprite.set_frame(1)
:bust_in_silhouette: Reply From: User457654654

I finally got it to work. Here’s the code I use, in case someone else might be able to use it.

    extends Area2D
    
    export var connected = false
    
    # Called when the node enters the scene tree for the first time. 
func _ready(): 	$AnimatedSprite.animation = "switch" 	$AnimatedSprite.set_frame(0)
    


func _on_Area2D_body_entered(body):
 	if body.name == "Object1" or body.name == "Object2":
 		connected = true
 		$AnimatedSprite.set_frame(1)