0 votes

Hey,

I am completely new to Godot and I have set a 2d camera with an animation that moves the camera to a certain point on the screen, but I am wondering how to allow the camera to automatically zoom in after the animation a stopped playing and how to load a new scene after the zoom in effect has stopped.

I have been searching the web to help with this but I can find an answer or even a tutorial.

Any help would be greatly appreciated and thanks in advance.

in Projects by (32 points)

1 Answer

0 votes

Hello Kyle J144,

I assume that you have one animation, which animates the position of the camera between two positions, right?

So you could make another animation, which changes the property zoom of the camera to zoom in over time, like you already do with the position.

Then you can attach a script to your parents node, something like this:

# This script could be attached to your camera.
extends Camera2D

# Get a reference to the AnimationPlayer, which is a child of the camera.
onready var anim = $AnimationPlayer

func _ready( ):
    # Connects the AnimationPlayer with the signal "animation_finished" to the camera ('self' here)
    anim.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")

func _on_AnimationPlayer_animation_finished(animation):
    # Check the name of the animation, which is finished.
    # In your case the camera moving animation..
    if animation == "my_camera_move_animation":
        anim.play("zoom_in")

How it works:

Connect the signal animation_finished of the AnimationPlayer to your Node, where this script is attached (self). The signal fires, when the current played animation is finished. Then the method is called, which is specified in the connect function.
See Signals for more information.

_on_AnimationPlayer_animation_finished checks the name of the animation, which is played before. Make sure to use the right name here! Then tell the AnimationPlayer to play your "zoom_in" animation (or whatever animation you want to play).


I am completely new to Godot

I really suggest you to go through the Step by step guide from the docs.

Good Luck! :-)

by (248 points)
edited by

The zoom effect is not working :/

When i also check the error log. I am receiving this error

0:00:40:0358 - Animation not found: zoom_in

Type:Error
Description: Animation not found: zoomin
Time: 0:00:40:0358
C Error: Method/Function Failed.
C Source: scene/animation/animation
player.cpp:888
C Function: play

You need to create of course a new animation with the name "zoom_in" (you could name it whatever you want, but it needs to be the same name as in the script).

Here is a little tutorial about animations.

Yeah, but where is the zoom in effect, because on the inspector of the Animation Player. I have got an option for Zoom and when i increase of decrease the y and x on the zoom then it just stretches the image of shortens the image.

it just stretches the image of shortens the image.

Yes. This is normal behaviour with zooming in 2D games. Would you expect something else?

Yeah, but where is the zoom in effect, because on the inspector of the Animation Player. I have got an option for Zoom and [..]

You have to create a new animation. Then add a key at the beginning of the animation from the camera property zoom. Then later on the timeline you add another key with different values of the zoom property. Thats how you can create a basic "zoom-in"-effect.

Again, read the Step by step guide, especially for Animations.

Good luck! :-)

Thank you and how would i make it so that when the player loads back into the same scene. then animation doesn't play again

P.S sorry for all the questions

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.

Categories