reduce scale of sprite over time

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

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

:bust_in_silhouette: Reply From: jgodfrey

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();

thanks , look pretty obvious :slight_smile:

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

vickz | 2020-04-25 14:42