Skip to content

Commit

Permalink
add main menu videos
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn committed Aug 15, 2024
1 parent c8545ec commit 329fcb9
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 20 deletions.
6 changes: 6 additions & 0 deletions Godottest/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ config_version=5
config/name="videoproject"
run/main_scene="res://res/node_2d.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
boot_splash/bg_color=Color(0, 0, 0, 1)
boot_splash/show_image=false

[display]

window/size/viewport_width=1280
window/size/viewport_height=768
window/stretch/mode="viewport"

[rendering]

viewport/transparent_background=true
36 changes: 36 additions & 0 deletions Godottest/res/node.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends Node

var count = 0

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
play_next()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass


func play_next():
print(count)
get_next().start()
count += 1

func prep_next():
get_next().prep()

func get_next():

match count % 6:
0:
return $VideoStreamPlayer
1:
return $VideoStreamPlayer2
2:
return $VideoStreamPlayer3
3:
return $VideoStreamPlayer4
4:
return $VideoStreamPlayer5
5:
return $VideoStreamPlayer6
29 changes: 29 additions & 0 deletions Godottest/res/node_2d.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends Node2D

var alpha = 0

# Function to set the alpha for the parent and its children
func set_alpha(alpha_value: float) -> void:
# Ensure alpha_value is between 0 and 1
alpha_value = clamp(alpha_value, 0.0, 1.0)

# Set the parent's alpha if it has a Modulate property
if has_method("set_modulate"):
modulate = Color(modulate.r, modulate.g, modulate.b, alpha_value)

# Loop through each child
for child in get_children():
if child.has_method("set_modulate"):
var child_modulate = child.modulate
child.modulate = Color(child_modulate.r, child_modulate.g, child_modulate.b, alpha_value)

# Example function to change alpha
func _ready():
pass
#set_alpha(0.5) # Change all children's alpha to 0.5

func _process(_delta):

if alpha < 3.0:
alpha += 0.006;
set_alpha(alpha-2.0) # Change all children's alpha to 0.5
80 changes: 63 additions & 17 deletions Godottest/res/node_2d.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[gd_scene load_steps=6 format=3 uid="uid://pdkn35rn7rts"]
[gd_scene load_steps=12 format=3 uid="uid://pdkn35rn7rts"]

[ext_resource type="VideoStream" path="res://res/media/output.ogv" id="1_r13cb"]
[ext_resource type="Script" path="res://res/video_stream_player.gd" id="2_76rnb"]
[ext_resource type="Script" path="res://res/node_2d.gd" id="1_atssm"]
[ext_resource type="VideoStream" path="res://res/media/mainmenu-to-eyesclosedheadback.ogv" id="1_huc1b"]
[ext_resource type="VideoStream" path="res://res/media/mainmenu-from-walkin.ogv" id="1_ila7w"]
[ext_resource type="Script" path="res://res/node.gd" id="1_ypcjg"]
[ext_resource type="Script" path="res://res/vsp.gd" id="2_v4qc7"]
[ext_resource type="VideoStream" path="res://res/media/mainmenu-from-backofhead.ogv" id="5_3gsv2"]
[ext_resource type="VideoStream" path="res://res/media/mainmenu-to-lookdownandup.ogv" id="6_3pm7c"]
[ext_resource type="VideoStream" path="res://res/media/mainmenu-to-lookdownandshrug.ogv" id="7_g2nyq"]

[sub_resource type="Theme" id="Theme_pqtiu"]
default_font_size = 36
Expand All @@ -15,21 +21,61 @@ default_font_size = 55

[node name="Node2D" type="Node2D"]

[node name="ColorRect" type="ColorRect" parent="."]
offset_right = 1471.0
offset_bottom = 824.0
color = Color(0, 0, 0, 1)
[node name="Node" type="Node" parent="."]
script = ExtResource("1_ypcjg")

[node name="VideoStreamPlayer" type="VideoStreamPlayer" parent="."]
[node name="VideoStreamPlayer6" type="VideoStreamPlayer" parent="Node"]
offset_right = 1280.0
offset_bottom = 768.0
stream = ExtResource("1_r13cb")
stream = ExtResource("7_g2nyq")
volume_db = -80.0
autoplay = true
loop = true
script = ExtResource("2_76rnb")
script = ExtResource("2_v4qc7")
fadein = false

[node name="Label" type="Label" parent="."]
[node name="VideoStreamPlayer5" type="VideoStreamPlayer" parent="Node"]
offset_right = 1280.0
offset_bottom = 768.0
stream = ExtResource("5_3gsv2")
volume_db = -80.0
script = ExtResource("2_v4qc7")
fadeout = false

[node name="VideoStreamPlayer4" type="VideoStreamPlayer" parent="Node"]
offset_right = 1280.0
offset_bottom = 768.0
stream = ExtResource("6_3pm7c")
volume_db = -80.0
script = ExtResource("2_v4qc7")
fadein = false

[node name="VideoStreamPlayer3" type="VideoStreamPlayer" parent="Node"]
offset_right = 1280.0
offset_bottom = 768.0
stream = ExtResource("5_3gsv2")
volume_db = -80.0
script = ExtResource("2_v4qc7")
fadeout = false

[node name="VideoStreamPlayer2" type="VideoStreamPlayer" parent="Node"]
offset_right = 1280.0
offset_bottom = 768.0
stream = ExtResource("1_huc1b")
volume_db = -80.0
script = ExtResource("2_v4qc7")
fadein = false

[node name="VideoStreamPlayer" type="VideoStreamPlayer" parent="Node"]
offset_right = 1280.0
offset_bottom = 768.0
stream = ExtResource("1_ila7w")
volume_db = -80.0
script = ExtResource("2_v4qc7")
fadeout = false

[node name="Node2D" type="Node2D" parent="Node"]
script = ExtResource("1_atssm")

[node name="Label" type="Label" parent="Node/Node2D"]
offset_left = 724.0
offset_top = 374.0
offset_right = 956.0
Expand All @@ -38,7 +84,7 @@ theme = SubResource("Theme_pqtiu")
text = "⇒ New Game"
horizontal_alignment = 2

[node name="Label4" type="Label" parent="."]
[node name="Label4" type="Label" parent="Node/Node2D"]
offset_left = 767.0
offset_top = 326.0
offset_right = 957.0
Expand All @@ -47,7 +93,7 @@ theme = SubResource("Theme_pqtiu")
text = "Continue"
horizontal_alignment = 2

[node name="Label5" type="Label" parent="."]
[node name="Label5" type="Label" parent="Node/Node2D"]
offset_left = 444.0
offset_top = 87.0
offset_right = 962.0
Expand All @@ -56,7 +102,7 @@ theme = SubResource("Theme_norqa")
text = "dungeon game"
horizontal_alignment = 2

[node name="Label2" type="Label" parent="."]
[node name="Label2" type="Label" parent="Node/Node2D"]
offset_left = 766.0
offset_top = 423.0
offset_right = 956.0
Expand All @@ -65,7 +111,7 @@ theme = SubResource("Theme_pqtiu")
text = "Settings"
horizontal_alignment = 2

[node name="Label3" type="Label" parent="."]
[node name="Label3" type="Label" parent="Node/Node2D"]
offset_left = 763.0
offset_top = 473.0
offset_right = 953.0
Expand Down
10 changes: 7 additions & 3 deletions Godottest/res/video_stream_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ var fade_direction = 0.02

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.


self.connect("finished", Callable(self, "_on_video_finished"))
self.play()
#self.paused=1

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
#modulate.a+=fade_direction
if modulate.a > 1.0 || modulate.a < 0.0: fade_direction=-fade_direction
pass

func _on_video_finished():
self.get_parent().play_next()
49 changes: 49 additions & 0 deletions Godottest/res/vsp.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extends VideoStreamPlayer

@export var fadeout: bool = true
@export var fadein: bool = true
@export var streamlength: float = 10.

func _ready() -> void:
self.connect("finished", Callable(self, "_on_video_finished"))
self.play()
self.paused=1
#if fadein:
modulate.a = 0

func prep():
modulate.a = 1

func start():
self.paused=0
if fadein == false:
modulate.a = 1

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
if fadein && self.paused==false:
if modulate.a < 1.0:
modulate.a += 0.03

if fadeout == false && self.stream_position > streamlength/2:
get_parent().prep_next()

if fadeout && self.stream_position > streamlength/2:
if self.stream_position > streamlength - 0.5:
modulate.a -= 0.05
if modulate.a <= 0:
stop()
play()
paused=1
get_parent().play_next()
else:
modulate.a=1

pass

func _on_video_finished():
modulate.a = 0
self.stop()
self.play()
self.paused=1
self.get_parent().play_next()

0 comments on commit 329fcb9

Please sign in to comment.