xiandie/scene/shading/fog.gd

51 lines
1.4 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name Fog2D extends AnimatedSprite2D
const FOG_COLOR_DEFAULT = Color(0.8, 0.8, 0.8, 0.8)
const FOG_COLOR_WHITE = Color(1, 1, 1, 1)
const FOG_COLOR_BLACK = Color(0, 0, 0, 1)
const FOG_COLOR_GRAY = Color(0.5, 0.5, 0.5, 1)
const FOG_COLOR_DARK_GRAY = Color(0.2, 0.2, 0.2, 1)
var FOG_FRAME_MIN = 0
var FOG_FRAME_MAX
var FOG_FRAME_DEFAULT
const FOG_OFFSET_DEFAULT = Vector2(0, 50)
func _ready() -> void:
FOG_FRAME_MAX = sprite_frames.get_frame_count(animation) - 1
FOG_FRAME_DEFAULT = FOG_FRAME_MAX
var _fog_tween: Tween
func tween_fog(
end_frame := frame,
end_modulate := modulate,
end_offset := offset,
duration := 0.8,
close_at_end := false
) -> void:
if not is_node_ready():
return
if GlobalConfig.DEBUG:
print(
"Tween fog to frame: ", end_frame, " modulate: ", end_modulate, " offset: ", end_offset
)
if not visible:
# 如果没有开启 fog先开启并且设置为透明
visible = true
modulate = Color.TRANSPARENT
if _fog_tween and _fog_tween.is_valid():
_fog_tween.kill()
_fog_tween = create_tween()
_fog_tween.tween_property(self, "frame", end_frame, duration)
if end_modulate != modulate:
_fog_tween.parallel().tween_property(self, "self_modulate", end_modulate, duration)
if end_offset != offset:
_fog_tween.parallel().tween_property(self, "offset", end_offset, duration)
if close_at_end:
_fog_tween.tween_callback(hide)