Skip to content

Commit

Permalink
Added scene transition (#51)
Browse files Browse the repository at this point in the history
* Make a scene transition autoload

* Make anim and temp script

* Make simple script

* Add scenetrans to autoload

* added it to autoload

* Fixed the bug where ui is weird

* Added Transition to all

* Add it to luar rumah andika juga

* Addded trans to intro

* IDK FIXED SOME BUGS ????

* idk fixing bugs

* Bug fixed
  • Loading branch information
AgilMonkey authored Jun 1, 2024
1 parent c4ef3bd commit 192f487
Show file tree
Hide file tree
Showing 18 changed files with 357 additions and 130 deletions.
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ config/icon="res://icon.svg"
LevelManager="*res://scenes/autoloads/level-manager/level_manager.tscn"
InteractManager="*res://scenes/autoloads/interact-manager/interact_manager.tscn"
Dialogic="*res://addons/dialogic/Core/DialogicGameHandler.gd"
SceneTransition="*res://scenes/autoloads/transition/scene_transition.tscn"

[dialogic]

Expand Down
8 changes: 8 additions & 0 deletions scenes/autoloads/interact-manager/interact_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ var can_interact = true
var dialogic_layout = null


func _ready():
LevelManager.changing_scene_started.connect(func(): active_areas = [])
SceneTransition.transition_started.connect(func(): can_interact = false)
SceneTransition.transition_ended.connect(func(): can_interact = true)


func register_area(area: InteractArea):
active_areas.push_back(area)

Expand All @@ -18,6 +24,8 @@ func register_area(area: InteractArea):
func unregister_area(area: InteractArea):
area.hide_interact_icon()
active_areas.erase(area)
#if area.name == "Area2DToDapur":
#print(active_areas)


func _process(delta):
Expand Down
16 changes: 16 additions & 0 deletions scenes/autoloads/level-manager/level_manager.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
extends Node


signal changing_scene_started
signal changing_scene_ended

var from: String # Variabel buat memberitahu ruang sebelumnya

var is_changing_scene := false


func change_scene_with_transition(packed_scene: PackedScene):
if is_changing_scene:
return

is_changing_scene = true
SceneTransition.start_transition(SceneTransition.FADE_TO_BLACK)
await SceneTransition.transition_in_middle
get_tree().call_deferred("change_scene_to_packed", packed_scene)
is_changing_scene = false
26 changes: 26 additions & 0 deletions scenes/autoloads/transition/scene_transition.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends CanvasLayer


var current_transition

signal transition_started
signal transition_in_middle
signal transition_ended

const FADE_TO_BLACK = "FadeToBlack"


func start_transition(trans_name: String):
current_transition = find_child(trans_name)
current_transition.begin_animation()
transition_started.emit()


func transition_middle():
transition_in_middle.emit()
await get_tree().create_timer(0.4).timeout
current_transition.end_animation()


func end_transition():
transition_ended.emit()
141 changes: 141 additions & 0 deletions scenes/autoloads/transition/scene_transition.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
[gd_scene load_steps=7 format=3 uid="uid://dm41oxdpp22wt"]

[ext_resource type="Script" path="res://scenes/autoloads/transition/scene_transition.gd" id="1_ffkmw"]
[ext_resource type="Script" path="res://scenes/autoloads/transition/transition.gd" id="2_vhvhu"]

[sub_resource type="Animation" id="Animation_lm21w"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0, 0, 0, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}

[sub_resource type="Animation" id="Animation_qce8u"]
resource_name = "begin"
length = 0.4
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("..")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.39),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"transition_middle"
}]
}

[sub_resource type="Animation" id="Animation_dmm2k"]
resource_name = "end"
length = 0.4
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [true, false]
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("..")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.4),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"end_transition"
}]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_dqo75"]
_data = {
"RESET": SubResource("Animation_lm21w"),
"begin": SubResource("Animation_qce8u"),
"end": SubResource("Animation_dmm2k")
}

[node name="SceneTransition" type="CanvasLayer"]
script = ExtResource("1_ffkmw")
metadata/_edit_lock_ = true

[node name="FadeToBlack" type="ColorRect" parent="."]
visible = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 1)
script = ExtResource("2_vhvhu")

[node name="AnimationPlayer" type="AnimationPlayer" parent="FadeToBlack"]
libraries = {
"": SubResource("AnimationLibrary_dqo75")
}
12 changes: 12 additions & 0 deletions scenes/autoloads/transition/transition.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends ColorRect


@onready var animation_player := $AnimationPlayer


func begin_animation():
animation_player.play("begin")


func end_animation():
animation_player.play("end")
7 changes: 6 additions & 1 deletion scenes/interactable/change-level/interact_change_scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ extends InteractArea

signal change_scene

var is_changing_scene: bool


func _ready():
interact = func():
change_scene.emit()
if not is_changing_scene:
change_scene.emit()
is_changing_scene = true
await SceneTransition.transition_in_middle
4 changes: 4 additions & 0 deletions scenes/levels/dapur-01/dapur_01.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ func _ready():

func _on_area_2d_ke_ruang_tamu_body_entered(body):
LevelManager.from = "Dapur"
$Player.set_process_input(false)
$Player.direction = Vector2.ZERO
SceneTransition.start_transition("FadeToBlack")
await SceneTransition.transition_in_middle
get_tree().change_scene_to_file(scene_ruang_tamu)
4 changes: 4 additions & 0 deletions scenes/levels/kamar-andika-01/kamar_andika_01.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ func _ready():

func _on_area_2d_ke_ruang_tamu_body_entered(body):
LevelManager.from = "KamarAndika"
SceneTransition.start_transition("FadeToBlack")
$Player.set_process_input(false)
$Player.direction = Vector2.ZERO
await SceneTransition.transition_in_middle
get_tree().change_scene_to_file(scene_ruang_tamu)
4 changes: 4 additions & 0 deletions scenes/levels/luar-rumah-andika-01/LuarRumahAndika01.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ func _ready():

func _on_area_2d_to_ruang_tamu_on_change_scene():
LevelManager.from = "LuarRumahAndika"
$Player.set_process_input(false)
$Player.direction = Vector2.ZERO
SceneTransition.start_transition("FadeToBlack")
await SceneTransition.transition_in_middle
get_tree().change_scene_to_file(scene_ruang_tamu)
6 changes: 3 additions & 3 deletions scenes/levels/luar-rumah-andika-01/LuarRumahAndika01.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ position = Vector2(0, -80)
position = Vector2(-22, 208)

[node name="Player" parent="." instance=ExtResource("2_vqacv")]
position = Vector2(688, 664)
position = Vector2(560, 664)

[node name="PhantomCamera2D" type="Node2D" parent="." node_paths=PackedStringArray("follow_target")]
position = Vector2(688, 384)
position = Vector2(560, 384)
script = ExtResource("3_omytb")
follow_mode = 2
follow_target = NodePath("../Player")
Expand All @@ -106,7 +106,7 @@ follow_damping = true
draw_limits = true

[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(688, 384)
position = Vector2(560, 384)

[node name="PhantomCameraHost" type="Node" parent="Camera2D"]
script = ExtResource("3_lykbd")
Expand Down
Loading

0 comments on commit 192f487

Please sign in to comment.