How to set an automatic zoom in

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


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.

:bust_in_silhouette: Reply From: RenenerG

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":"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! :slight_smile:

The zoom effect is not working :confused:

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

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

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

Kyle J144 | 2019-02-23 13:34

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.

RenenerG | 2019-02-24 11:12

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.

Kyle J144 | 2019-02-24 11:42

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! :slight_smile:

RenenerG | 2019-02-24 23:15

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

Kyle J144 | 2019-02-25 08:43