+1 vote

I have created a simple shooting game. Mid of the game, player can level up automatically. To give better user experience on level up I tried to change the background color of ColorRect with following code.

extends ColorRect

  var totalTime = 0
  var endTime = 25

   func _process(delta):
      if Globals.State == Globals.GameState.Running:
           totalTime += delta
           if totalTime > endTime:
              totalTime = 0
              var r = rand_range(50, 200) / 255
              var g = rand_range(50, 200) / 255
              var b = rand_range(50, 200) / 255

This code working fine and changing color of the ColorRect instantly. I do not want the instant color changing behavior. I want the color should be changed smoothly over time with animation.

How to achieve this.
Thanks in advance.

in Engine by (109 points)

1 Answer

+1 vote
Best answer

This is very easy to achieve with the Tween node. The code would be something like this:


This would animate the current color to red with a duration of 2 seconds.

If you need help, let me know.

by (1,433 points)
selected 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.