Expo easing function + welcome screen
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
[gd_scene format=3 uid="uid://57px5totoewp"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://57px5totoewp"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://mgj6wd25jrsn" path="res://Scripts/WelcomeScreen/welcome_screen.gd" id="1_5gy0r"]
|
||||
|
||||
[node name="WelcomeScreen" type="CanvasLayer"]
|
||||
script = ExtResource("1_5gy0r")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchors_preset = 15
|
||||
|
||||
43
game/Scripts/WelcomeScreen/welcome_screen.gd
Normal file
43
game/Scripts/WelcomeScreen/welcome_screen.gd
Normal file
@@ -0,0 +1,43 @@
|
||||
extends CanvasLayer
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
update_progress_bar(80)
|
||||
|
||||
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
func update_progress_bar(value: float):
|
||||
var start_value = $ProgressBar.value
|
||||
var percent = 0
|
||||
|
||||
while percent < 100:
|
||||
var ease = expo_ease_in_out(start_value, value, percent)
|
||||
$ProgressBar.value = ease
|
||||
percent += 1
|
||||
await get_tree().create_timer(0.05).timeout
|
||||
|
||||
|
||||
|
||||
func expo_ease_in_out(start: float, end: float, percent: int) -> float:
|
||||
var t: float = clamp(float(percent) / 100.0, 0, 1.0)
|
||||
var change: float = end - start
|
||||
|
||||
if t == 0:
|
||||
return start
|
||||
if t == 1.0:
|
||||
return end
|
||||
|
||||
if t < 0.5:
|
||||
return change / 2 * pow(2, 20 * t - 10) + start
|
||||
else:
|
||||
return change / 2 * (-pow(2, -20 * t + 10) + 2) + start
|
||||
1
game/Scripts/WelcomeScreen/welcome_screen.gd.uid
Normal file
1
game/Scripts/WelcomeScreen/welcome_screen.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://mgj6wd25jrsn
|
||||
Reference in New Issue
Block a user