Un shader de transition entre les scènes
ça fait plus propre braw
This commit is contained in:
@@ -22,7 +22,6 @@ func _ready() -> void:
|
||||
cam.limit_bottom = bottom_right_global.y - 24
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
print(human.get_feet_global_position())
|
||||
human.stop_interaction()
|
||||
human.velocityVector = Vector2(0, 0)
|
||||
human.wants_to_grab = false
|
||||
@@ -30,7 +29,6 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
human.velocityVector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
if human.velocityVector != Vector2(0, 0):
|
||||
GameState.isUsingTouch = false
|
||||
else:
|
||||
update_game_state()
|
||||
|
||||
if event.is_action_pressed("grab"):
|
||||
|
||||
@@ -22,6 +22,7 @@ func update_position(p: Vector2):
|
||||
position_outside = p
|
||||
"bakery":
|
||||
position_bakery = p
|
||||
print (current_scene, " position ", p)
|
||||
|
||||
func save():
|
||||
var ret = {}
|
||||
|
||||
@@ -8,6 +8,7 @@ func _ready() -> void:
|
||||
load_from_game_state()
|
||||
|
||||
func load_from_game_state():
|
||||
print("setting player in bakery at ", GameState.position_bakery)
|
||||
$Bakery/player.set_feet_global_position(GameState.position_bakery)
|
||||
emit_signal("loadFromGameState")
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ class_name GameControler
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("menu"):
|
||||
if prev_scene == menu:
|
||||
start_game()
|
||||
else:
|
||||
open_menu()
|
||||
|
||||
# list of scenes
|
||||
@@ -11,41 +14,46 @@ var dest_outside = preload("res://scenes/outside.tscn")
|
||||
var bakery:Node2D = null
|
||||
var dest_bakery = preload("res://scenes/bakery_interior.tscn")
|
||||
var menu = null
|
||||
var prev_scene = null
|
||||
|
||||
func _ready() -> void:
|
||||
GameState._game = self
|
||||
menu = get_child(0)
|
||||
prev_scene = menu
|
||||
|
||||
func start_game():
|
||||
menu = get_child(0)
|
||||
switch_to(GameState.current_scene)
|
||||
|
||||
func switch_to(to: String):
|
||||
call_deferred("switch_scene", to)
|
||||
|
||||
var next_scene = null
|
||||
var toMenu = false;
|
||||
var switching_to
|
||||
|
||||
func switch_scene(to: String):
|
||||
var prev = get_child(0)
|
||||
GameState.current_scene = to
|
||||
var scene
|
||||
switching_to= to
|
||||
print("switching to", switching_to)
|
||||
toMenu = to == "menu"
|
||||
match to:
|
||||
"outside":
|
||||
if outside == null:
|
||||
outside = dest_outside.instantiate()
|
||||
scene = outside
|
||||
next_scene = outside
|
||||
"bakery":
|
||||
if bakery == null:
|
||||
bakery = dest_bakery.instantiate()
|
||||
scene = bakery
|
||||
scene.unload()
|
||||
call_deferred("add_child", scene)
|
||||
call_deferred("remove_child", prev)
|
||||
call_deferred("init_scence", scene)
|
||||
next_scene = bakery
|
||||
"menu":
|
||||
next_scene = menu
|
||||
$TransitionShader.fade_out()
|
||||
|
||||
func init_scence(scene):
|
||||
scene.load_from_game_state()
|
||||
$TransitionShader.fade_in()
|
||||
|
||||
func open_menu():
|
||||
remove_child(get_child(0))
|
||||
add_child(menu)
|
||||
switch_scene("menu")
|
||||
|
||||
func load_game():
|
||||
var save_file = FileAccess.open("user://savegame.save", FileAccess.READ)
|
||||
@@ -62,3 +70,19 @@ func save_game():
|
||||
save_file.store_line(JSON.stringify(GameState.save(), " ", true, true))
|
||||
print(OS.get_data_dir())
|
||||
save_file.close()
|
||||
|
||||
func _on_transition_shader_fade_in_done() -> void:
|
||||
if !toMenu:
|
||||
GameState.current_scene = switching_to
|
||||
|
||||
func _on_transition_shader_fade_out_done() -> void:
|
||||
print("fade out done")
|
||||
if !toMenu:
|
||||
next_scene.unload()
|
||||
call_deferred("add_child", next_scene)
|
||||
call_deferred("remove_child", prev_scene)
|
||||
if !toMenu:
|
||||
call_deferred("init_scence", next_scene)
|
||||
else:
|
||||
$TransitionShader.fade_in()
|
||||
prev_scene = next_scene
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c645h6ap7niu1"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c645h6ap7niu1"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://44wla7mlivqm" path="res://UI/menu.tscn" id="1_64gp8"]
|
||||
[ext_resource type="Script" path="res://scenes/game.gd" id="1_b2ju7"]
|
||||
[ext_resource type="PackedScene" uid="uid://17macg0q4k8l" path="res://shaders/transition_shader.tscn" id="3_2p7jc"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
script = ExtResource("1_b2ju7")
|
||||
|
||||
[node name="Menu" parent="." instance=ExtResource("1_64gp8")]
|
||||
|
||||
[node name="TransitionShader" parent="." instance=ExtResource("3_2p7jc")]
|
||||
|
||||
[connection signal="load" from="Menu" to="." method="load_game"]
|
||||
[connection signal="save" from="Menu" to="." method="save_game"]
|
||||
[connection signal="start" from="Menu" to="." method="start_game"]
|
||||
[connection signal="fade_in_done" from="TransitionShader" to="." method="_on_transition_shader_fade_in_done"]
|
||||
[connection signal="fade_out_done" from="TransitionShader" to="." method="_on_transition_shader_fade_out_done"]
|
||||
|
||||
BIN
shaders/masks/curtain.png
Normal file
BIN
shaders/masks/curtain.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 146 KiB |
36
shaders/masks/curtain.png.import
Normal file
36
shaders/masks/curtain.png.import
Normal file
@@ -0,0 +1,36 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b5mne7k2hxq4m"
|
||||
path.s3tc="res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex"
|
||||
path.etc2="res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.etc2.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc", "etc2_astc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://shaders/masks/curtain.png"
|
||||
dest_files=["res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex", "res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.etc2.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
BIN
shaders/masks/shards.png
Normal file
BIN
shaders/masks/shards.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 81 KiB |
36
shaders/masks/shards.png.import
Normal file
36
shaders/masks/shards.png.import
Normal file
@@ -0,0 +1,36 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dwn3g5smhhcb0"
|
||||
path.s3tc="res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex"
|
||||
path.etc2="res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.etc2.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc", "etc2_astc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://shaders/masks/shards.png"
|
||||
dest_files=["res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex", "res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.etc2.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
20
shaders/transition_shader.gd
Normal file
20
shaders/transition_shader.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends CanvasLayer
|
||||
|
||||
signal fade_in_done()
|
||||
signal fade_out_done()
|
||||
|
||||
@onready var player := $TransitionShader/AnimationPlayer as AnimationPlayer
|
||||
|
||||
func fade_in():
|
||||
player.play(&"fade_in")
|
||||
|
||||
func fade_out():
|
||||
visible = true
|
||||
player.play(&"fade_out")
|
||||
|
||||
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
||||
if anim_name == "fade_in":
|
||||
fade_in_done.emit()
|
||||
visible = false
|
||||
elif anim_name == "fade_out":
|
||||
fade_out_done.emit()
|
||||
16
shaders/transition_shader.gdshader
Normal file
16
shaders/transition_shader.gdshader
Normal file
@@ -0,0 +1,16 @@
|
||||
shader_type canvas_item;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform float cutoff: hint_range(0.0, 1.0);
|
||||
uniform float smooth_size: hint_range(0.0, 0.1);
|
||||
uniform sampler2D mask: hint_default_black;
|
||||
|
||||
void fragment() {
|
||||
float value = texture(mask, UV).r;
|
||||
float alpha = smoothstep(
|
||||
cutoff,
|
||||
cutoff + smooth_size,
|
||||
value * (1.0 - smooth_size) + smooth_size
|
||||
);
|
||||
COLOR = vec4(COLOR.rgb, alpha);
|
||||
}
|
||||
71
shaders/transition_shader.tscn
Normal file
71
shaders/transition_shader.tscn
Normal file
@@ -0,0 +1,71 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://17macg0q4k8l"]
|
||||
|
||||
[ext_resource type="Script" path="res://shaders/transition_shader.gd" id="1_aj5xt"]
|
||||
[ext_resource type="Shader" path="res://shaders/transition_shader.gdshader" id="1_kyfmm"]
|
||||
[ext_resource type="Texture2D" uid="uid://b5mne7k2hxq4m" path="res://shaders/masks/curtain.png" id="2_pg1r4"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_g48os"]
|
||||
shader = ExtResource("1_kyfmm")
|
||||
shader_parameter/cutoff = 0.0
|
||||
shader_parameter/smooth_size = 0.1
|
||||
shader_parameter/mask = ExtResource("2_pg1r4")
|
||||
|
||||
[sub_resource type="Animation" id="Animation_yg4ht"]
|
||||
resource_name = "fade_in"
|
||||
length = 0.5
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:material:shader_parameter/cutoff")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.2, 0.4),
|
||||
"transitions": PackedFloat32Array(1, 0.450625),
|
||||
"update": 0,
|
||||
"values": [0.0, 1.0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_mavdc"]
|
||||
resource_name = "fade_out"
|
||||
length = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:material:shader_parameter/cutoff")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [1.0, 0.0]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_kedvi"]
|
||||
_data = {
|
||||
"fade_in": SubResource("Animation_yg4ht"),
|
||||
"fade_out": SubResource("Animation_mavdc")
|
||||
}
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer"]
|
||||
visible = false
|
||||
script = ExtResource("1_aj5xt")
|
||||
|
||||
[node name="TransitionShader" type="ColorRect" parent="."]
|
||||
material = SubResource("ShaderMaterial_g48os")
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="TransitionShader"]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_kedvi")
|
||||
}
|
||||
|
||||
[connection signal="animation_finished" from="TransitionShader/AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
|
||||
@@ -563,6 +563,7 @@ debugLabel = NodePath("Label")
|
||||
texture = ExtResource("4_0kman")
|
||||
hframes = 12
|
||||
vframes = 4
|
||||
frame = 46
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
root_node = NodePath("../..")
|
||||
@@ -588,6 +589,7 @@ shape = SubResource("CapsuleShape2D_l8rwt")
|
||||
position = Vector2(1, 2)
|
||||
rotation = -3.14159
|
||||
shape = SubResource("CapsuleShape2D_l8rwt")
|
||||
disabled = true
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_left = 72.0
|
||||
|
||||
Reference in New Issue
Block a user