Godot Version
4.1
Question
Hi, everyone. I’m trying to create a transition between two textures using tween. My code changes the texture after 1 second as I defined. However, the code doesn’t do it smoothly. It’s just a sudden change after 1 second. I’m doing it like this:
extends Area2D
var target_texture: Texture
func _ready():
target_texture = preload("res://icon_selected.png")
$Sprite2D.material.set_shader_parameter("weight", 0)
$Sprite2D.material.set_shader_parameter("target_texture", target_texture)
func _on_mouse_entered():
var tween = create_tween()
tween.tween_property($Sprite2D.material, "shader_parameter/weight", 1.0, 1).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_SINE)
func _on_mouse_exited():
var tween = create_tween()
tween.tween_property($Sprite2D.material, "shader_parameter/weight", 0, 1).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_SINE)
Shader:
shader_type canvas_item;
uniform sampler2D target_texture;
uniform float weight: hint_range(0, 1);
void fragment()
{
vec4 color_a = texture(TEXTURE, UV);
vec4 color_b = texture(target_texture, UV);
COLOR = mix(color_a, color_b, weight);
}