FADE SYSTEM :3

This commit is contained in:
Haze Weathers 2023-02-21 13:40:49 -05:00
parent 4cd2018b2c
commit d27d9d8b83
8 changed files with 169 additions and 1 deletions

View file

@ -6,6 +6,9 @@
[ext_resource path="res://scripts/crt.gdshader" type="Shader" id=4] [ext_resource path="res://scripts/crt.gdshader" type="Shader" id=4]
[ext_resource path="res://scripts/2ndpuberty_no_dropshadow.tres" type="Theme" id=5] [ext_resource path="res://scripts/2ndpuberty_no_dropshadow.tres" type="Theme" id=5]
[ext_resource path="res://scripts/2ndpuberty_outline.tres" type="Material" id=6] [ext_resource path="res://scripts/2ndpuberty_outline.tres" type="Material" id=6]
[ext_resource path="res://graphics/fade_patterns/diamonds.png" type="Texture" id=7]
[ext_resource path="res://scripts/fade.gd" type="Script" id=8]
[ext_resource path="res://scripts/fade.gdshader" type="Shader" id=9]
[sub_resource type="ShaderMaterial" id=1] [sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 4 ) shader = ExtResource( 4 )
@ -15,6 +18,43 @@ shader_param/curvature = Vector2( 6, 6 )
shader_param/scanline_opacity = Vector2( 0.4, 0.05 ) shader_param/scanline_opacity = Vector2( 0.4, 0.05 )
shader_param/brightness = 1.25 shader_param/brightness = 1.25
[sub_resource type="ShaderMaterial" id=6]
shader = ExtResource( 9 )
shader_param/color = Color( 0, 0, 0, 1 )
shader_param/smooth_mode = false
shader_param/reverse = false
shader_param/opacity = 0.0
[sub_resource type="Animation" id=7]
resource_name = "FadeIn"
tracks/0/type = "value"
tracks/0/path = NodePath("TextureRect:material:shader_param/opacity")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 1.0, 0.0 ]
}
[sub_resource type="Animation" id=8]
resource_name = "FadeOut"
tracks/0/type = "value"
tracks/0/path = NodePath("TextureRect:material:shader_param/opacity")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[node name="Control" type="Control"] [node name="Control" type="Control"]
pause_mode = 2 pause_mode = 2
anchor_right = 1.0 anchor_right = 1.0
@ -52,7 +92,7 @@ render_target_update_mode = 3
[node name="LevelSelect" parent="ViewportContainer/Viewport" instance=ExtResource( 3 )] [node name="LevelSelect" parent="ViewportContainer/Viewport" instance=ExtResource( 3 )]
[node name="CheatLayer" type="CanvasLayer" parent="ViewportContainer/Viewport"] [node name="CheatLayer" type="CanvasLayer" parent="ViewportContainer/Viewport"]
layer = 127 layer = 120
[node name="CheatLabel" type="Label" parent="ViewportContainer/Viewport/CheatLayer"] [node name="CheatLabel" type="Label" parent="ViewportContainer/Viewport/CheatLayer"]
material = ExtResource( 6 ) material = ExtResource( 6 )
@ -63,3 +103,22 @@ margin_bottom = -5.0
theme = ExtResource( 5 ) theme = ExtResource( 5 )
align = 2 align = 2
valign = 2 valign = 2
[node name="FadeLayer" type="CanvasLayer" parent="ViewportContainer/Viewport"]
pause_mode = 2
layer = 128
script = ExtResource( 8 )
[node name="TextureRect" type="TextureRect" parent="ViewportContainer/Viewport/FadeLayer"]
material = SubResource( 6 )
margin_right = 255.994
margin_bottom = 192.0
texture = ExtResource( 7 )
expand = true
stretch_mode = 6
[node name="AnimationPlayer" type="AnimationPlayer" parent="ViewportContainer/Viewport/FadeLayer"]
anims/FadeIn = SubResource( 7 )
anims/FadeOut = SubResource( 8 )
[connection signal="animation_finished" from="ViewportContainer/Viewport/FadeLayer/AnimationPlayer" to="ViewportContainer/Viewport/FadeLayer" method="_fade_finished"]

View file

@ -5,6 +5,7 @@ onready var viewport = get_parent().get_node("Main/Control/ViewportContainer/Vie
var current_sector = Vector2(0,0) var current_sector = Vector2(0,0)
var fullscreen = false var fullscreen = false
#Onreadys #Onreadys
onready var fade = viewport.get_node("FadeLayer")
onready var viewport_container = get_parent().get_node("Main/Control/ViewportContainer") onready var viewport_container = get_parent().get_node("Main/Control/ViewportContainer")
#Collectibles #Collectibles
var golds = 0 var golds = 0
@ -77,6 +78,11 @@ func get_map():
#Go to new map #Go to new map
func change_map(map): func change_map(map):
get_tree().paused = true
can_pause = false
fade.fade_out(0.4)
yield(fade, "fade_finished")
can_pause = true
clear_collectibles() clear_collectibles()
#Loop is so no more than one level is loaded at a time #Loop is so no more than one level is loaded at a time
for maps in get_tree().get_nodes_in_group("map"): for maps in get_tree().get_nodes_in_group("map"):

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/diamonds.png-1b6afccd789d89c964ce5cbd8de4f0ae.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/fade_patterns/diamonds.png"
dest_files=[ "res://.import/diamonds.png-1b6afccd789d89c964ce5cbd8de4f0ae.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -31,6 +31,7 @@ export var target_time_any = 0
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
Game.fade.fade_in(0.000000000000001)
change_current_level(Game.current_level) change_current_level(Game.current_level)
Game.ac_music.stop() Game.ac_music.stop()

View file

@ -9,6 +9,11 @@ var life_bonus = true
var collectible_bonus = false var collectible_bonus = false
func _ready(): func _ready():
get_tree().paused = true
Game.can_pause = false
Game.fade.fade_in(0.4)
Game.fade.connect("fade_finished", get_tree(), "set_pause", [false], CONNECT_ONESHOT)
Game.fade.connect("fade_finished", Game, "set", ["can_pause", true], CONNECT_ONESHOT)
Game.play_music(music) Game.play_music(music)
func _physics_process(delta): func _physics_process(delta):

18
scripts/fade.gd Normal file
View file

@ -0,0 +1,18 @@
extends CanvasLayer
signal fade_finished
func fade_in(time, reverse = false, color = Color.black):
var rect = $TextureRect
rect.material.set_shader_param("color", color)
rect.material.set_shader_param("reverse", reverse)
$AnimationPlayer.play("FadeIn", -1, 1.0 / time)
func fade_out(time, reverse = false, color = Color.black):
var rect = $TextureRect
rect.material.set_shader_param("color", color)
rect.material.set_shader_param("reverse", reverse)
$AnimationPlayer.play("FadeOut", -1, 1.0 / time)
func _fade_finished(anim_name):
emit_signal("fade_finished")

44
scripts/fade.gdshader Normal file
View file

@ -0,0 +1,44 @@
shader_type canvas_item;
/*
MIT License
Copyright (c) 2019 Tomek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
uniform vec4 color : hint_color;
uniform bool smooth_mode = false;
uniform bool reverse = false;
uniform float opacity : hint_range(0, 1);
void fragment() {
float alpha = texture(TEXTURE, UV).r;
if (reverse) {
alpha = clamp(1.0 - alpha, 0.0, 1.0);
}
if (smooth_mode) {
alpha = mix(0.0, 1.0, clamp(alpha - 1.0 + opacity * 2.0, 0.0, 1.0));
} else {
alpha = clamp(ceil(alpha + opacity * 1.00001 - 1.0), 0.0, 1.0);
}
COLOR = vec4(color.rgb, alpha);
}