0 votes

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.

in Engine by (12 points)

2 Answers

+1 vote
by (2,470 points)
+1 vote

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
    set_process(true)
    circle.show()

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
        set_process(false)
        circle.hide()
    else:
        # 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
        else:
            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 body.name == "Player":
    emit_signal("time_to_load_a_level")
....

# and then loading gets handled here
func load_a_level():
    get_tree().change_scene(loaded_scene)
by (169 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.