0 votes

Hello ,

I would like to reduce my sprite scale from 1 to 0 in 5 second time.

I have try with timer but without good result.

Thanks

asked Apr 25 in Engine by vickz (15 points)

1 Answer

+1 vote
Best answer

The most obvious ways to do it would be either with a Tween or an AnimationPlayer.

As an example, to use AnimationPlayer...

  • Add an AnimationPlayer node to your scene
  • Add a new animation to the player (scaleAnim in the below code)
  • Set the duration of the animation to 5 seconds
  • Add a keyframe at 0 seconds.
  • Set the sprite's scale to 1.0 at that keyframe
  • Add a keyframe at 5 seconds
  • Set the sprite's scale to 0.0 at that keyframe

To play the animation from code, just call the following from a script attached to the parent of the scene

$AnimationPlayer.play("scaleAnim")

To do it with a Tween would go something like this:

  • Add a Tween node to your scene.
  • Set up the scale tween using:

    $Tween.interpolate_property($Sprite, "scale", 1, 0, 5, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
    
  • Start the animation using:

    $Tween.start();
    
answered Apr 25 by jgodfrey (6,576 points)
edited Apr 25 by jgodfrey

thanks , look pretty obvious :)

my current solution was to us lerp_range to remap timer value to 0-1

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.