how do i play an animation and then use a function

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

i want to make a transition for my game where when the player hits a “trigger” (in quotation marks because i dont know if its the correct word to use here) a black circle will scale up to fill the screen, the level will transition and then the black circle will scale back down to nothing.

i have the script to change screens here:

but i dont know how to do the animation part
can anyone please help me? keep in mind i am very new to this so i may need a lot of detail to understand.

:bust_in_silhouette: Reply From: klaas

you have to learn about animations and signals.

Read this …
… and this …

:bust_in_silhouette: Reply From: ichster

The easiest way I can think of is to draw a Sprite that is a circle, and then adjust its scale over time. Check out this script example I made that will allow the sprite to grow and shrink the number of times you set in circle_cycle_count. In your case you will want to set circle_min_scale_size to 0.0. If you decide to use this make sure you understand it:

extends Sprite

onready var circle = self # could also do if sprite is a child: get_node("MyCircleSpriteNode")
export (float) var circle_scale_speed = 2.0
export (float, 0.0, 20.0) var circle_min_scale_size = 1.0
export (float, 0.0, 100.0) var circle_max_scale_size = 5.0
export (int) var circle_cycle_count = 1
onready var scale_amount = circle_min_scale_size

# this function starts the circle moving
func start_circle() -> void:
	scale_amount = circle_min_scale_size

func _process(delta):
	# change scale
	scale_amount += circle_scale_speed * delta
	# check if we have done enough rotations through linear cycle
	var current_cycle_number = 1 + int(scale_amount / (2.0 * circle_max_scale_size))
	if current_cycle_number > circle_cycle_count:
		# stop circle
		# find scale value between [0.0,circle_max_scale_size]
		var scale_scalar = circle_max_scale_size - abs(circle_max_scale_size - (scale_amount - (float(current_cycle_number - 1) * 2.0 * circle_max_scale_size)))
		# if we are under, add min value and handle on next iteration
		if scale_scalar < circle_min_scale_size:
			scale_amount += 2.0 * circle_min_scale_size
		# apply scale
			circle.scale = Vector2(1.0, 1.0) * scale_scalar

You can Instance this Scene wherever you want to do the animation. Then, you can either directly call it: $Circle.start_circle(), or set up a signal in the parent node:

signal time_to_load_a_level

func _ready():
    self.connect("time_to_load_a_level", self, "load_a_level")
    self.connect("time_to_load_a_level", $Circle, "start_circle")

# and then later in _physics_proccess
if == "Player":
# and then loading gets handled here
func load_a_level():