Refactored scene transition nodes
This commit is contained in:
parent
fb18309abf
commit
306ed04ae6
|
@ -9,6 +9,10 @@ extends Node2D
|
|||
@export var enter_time := 0.3
|
||||
@export var exit_time := 0.3
|
||||
@export var snap_to_floor := true
|
||||
## Accessed by other scripts
|
||||
@export var interactable := false
|
||||
## Does walking into the area activate the transition?
|
||||
@export var walkable := true
|
||||
|
||||
const INIT_GRACE := 0.1
|
||||
var init_grace_tmp := INIT_GRACE
|
||||
|
@ -28,17 +32,18 @@ func _ready():
|
|||
var nodes = get_tree().get_nodes_in_group("cross_scene")
|
||||
for n in nodes:
|
||||
if n.exit_point == name:
|
||||
n.global_position = global_position
|
||||
n.reset_camera()
|
||||
exit_post_fixup(n)
|
||||
# Make actor enter loose control and walk for walk_time seconds
|
||||
if exit_time != 0:
|
||||
make_walk(n, !enter_right, exit_time)
|
||||
exit_here(n)
|
||||
|
||||
func _physics_process(delta):
|
||||
init_grace_tmp -= delta
|
||||
|
||||
func exit_post_fixup(n):
|
||||
## Makes an actor exit at this point
|
||||
func exit_here(n):
|
||||
n.global_position = global_position
|
||||
n.reset_camera()
|
||||
# Make actor enter loose control and walk for walk_time seconds
|
||||
if exit_time != 0:
|
||||
make_walk(n, !enter_right, exit_time)
|
||||
await get_tree().create_timer(0.4).timeout
|
||||
n.fade(false, exit_time)
|
||||
if snap_to_floor:
|
||||
|
@ -53,3 +58,8 @@ func make_walk(n, walk_right, time):
|
|||
await get_tree().create_timer(time).timeout
|
||||
n.input_dir.x = 0
|
||||
n.in_control = true
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
if walkable:
|
||||
transition(body)
|
||||
|
|
10
global/SceneTransition.tscn
Normal file
10
global/SceneTransition.tscn
Normal file
|
@ -0,0 +1,10 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://b2awe6tx7xq0c"]
|
||||
|
||||
[ext_resource type="Script" path="res://global/SceneTransition.gd" id="1_x83w3"]
|
||||
|
||||
[node name="SceneTransition" type="Area2D" groups=["scene_transition"]]
|
||||
collision_layer = 256
|
||||
collision_mask = 4
|
||||
script = ExtResource("1_x83w3")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
|
@ -397,11 +397,12 @@ func _on_hurt_box_hurt(data):
|
|||
var current_interactable = null
|
||||
var interact_arrow = preload("res://global/ui/InteractArrow.tscn")
|
||||
func _on_interact_box_area_entered(area):
|
||||
if current_interactable != null:
|
||||
current_interactable.get_node("InteractArrow").queue_free()
|
||||
current_interactable = area
|
||||
var arrow_instance = interact_arrow.instantiate()
|
||||
current_interactable.add_child(arrow_instance)
|
||||
if area.interactable:
|
||||
if current_interactable != null:
|
||||
current_interactable.get_node("InteractArrow").queue_free()
|
||||
current_interactable = area
|
||||
var arrow_instance = interact_arrow.instantiate()
|
||||
current_interactable.add_child(arrow_instance)
|
||||
|
||||
func _on_interact_box_area_exited(area):
|
||||
if current_interactable == area:
|
||||
|
|
|
@ -54,6 +54,7 @@ debug_trail=""
|
|||
debug_enemy_respawn=""
|
||||
EntryPoint="A point in a scene which a transition may lead"
|
||||
cross_scene="Nodes that cross scenes between entry-points"
|
||||
scene_transition=""
|
||||
|
||||
[input]
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=12 format=4 uid="uid://cwp72vpwvgfur"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dlyt5o2dona1a" path="res://player/Player.tscn" id="1_lafxi"]
|
||||
[ext_resource type="Script" path="res://global/SceneTransition.gd" id="2_b6h25"]
|
||||
[ext_resource type="PackedScene" uid="uid://b2awe6tx7xq0c" path="res://global/SceneTransition.tscn" id="2_678xi"]
|
||||
[ext_resource type="Texture2D" uid="uid://bgw5itdndav4s" path="res://icon.svg" id="3_d5ovc"]
|
||||
[ext_resource type="Script" path="res://global/SceneCamera.gd" id="4_3h3kb"]
|
||||
[ext_resource type="Script" path="res://global/ExtraPhysicsAttributes.gd" id="6_6g8jl"]
|
||||
|
@ -33,28 +33,25 @@ editor_description = "No fancy graphics stuff here!"
|
|||
[node name="Player" parent="." instance=ExtResource("1_lafxi")]
|
||||
position = Vector2(2071, 786)
|
||||
|
||||
[node name="PointColorado" type="Area2D" parent="."]
|
||||
position = Vector2(3063, 705)
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
script = ExtResource("2_b6h25")
|
||||
[node name="PointColorado" parent="." instance=ExtResource("2_678xi")]
|
||||
position = Vector2(3133, 721)
|
||||
scene = "res://test_levels/test_bad_performance.tscn"
|
||||
exit_point = "PointMaine"
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="PointColorado"]
|
||||
position = Vector2(16, -4.5)
|
||||
position = Vector2(-11, 8)
|
||||
shape = SubResource("RectangleShape2D_6n8gr")
|
||||
|
||||
[node name="PointWyoming" type="Area2D" parent="."]
|
||||
position = Vector2(1450, 783)
|
||||
collision_layer = 256
|
||||
collision_mask = 0
|
||||
script = ExtResource("2_b6h25")
|
||||
[node name="PointWyoming" parent="." instance=ExtResource("2_678xi")]
|
||||
position = Vector2(1407, 771)
|
||||
scene = "res://test_levels/test_bad_performance.tscn"
|
||||
exit_point = "PointMaine"
|
||||
walk = false
|
||||
interactable = true
|
||||
walkable = false
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="PointWyoming"]
|
||||
position = Vector2(-3, 12)
|
||||
shape = SubResource("RectangleShape2D_6wgqt")
|
||||
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
||||
|
@ -83,5 +80,3 @@ no_wallslide = true
|
|||
[node name="Shape" type="CollisionShape2D" parent="NoSlide"]
|
||||
position = Vector2(117, 61)
|
||||
shape = SubResource("RectangleShape2D_bt30b")
|
||||
|
||||
[connection signal="body_entered" from="PointColorado" to="PointColorado" method="transition"]
|
||||
|
|
Loading…
Reference in a new issue