Skip to content

Commit

Permalink
add: button background music
Browse files Browse the repository at this point in the history
  • Loading branch information
KTools2202 authored and KTools2202 committed Jul 10, 2024
1 parent 9bf262a commit 1de4b03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion scenes/start_button.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://ij081mw11vmd"]
[gd_scene load_steps=5 format=3 uid="uid://ij081mw11vmd"]

[ext_resource type="Script" path="res://scripts/scene_transition.gd" id="1_0qwew"]
[ext_resource type="Texture2D" uid="uid://dv8rqv5yof8nd" path="res://sprites/Start button unclicked.png" id="1_u3ucj"]
[ext_resource type="AudioStream" uid="uid://dfaswthopohch" path="res://audio/The Journey (final ver.).mp3" id="2_5pfl5"]
[ext_resource type="Texture2D" uid="uid://g0prqcwksx5u" path="res://sprites/Start button clicked.png" id="2_32y8s"]

[node name="Control" type="Control"]
Expand All @@ -17,6 +18,9 @@ grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_0qwew")

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_5pfl5")

[node name="TextureButton" type="TextureButton" parent="."]
layout_mode = 0
offset_top = 5.0
Expand Down
14 changes: 9 additions & 5 deletions scripts/scene_transition.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
extends Control

func _ready():
# Access the TextureButton node
var button_node = $TextureButton # Assumes TextureButton is a child node of Control

@onready var audio_player = $AudioStreamPlayer
@onready var button_node = $TextureButton

func _ready():
# Check if button_node is valid before connecting
if button_node:
# Play audio once scene is ready
audio_player.play()
# Connect the 'pressed' signal from TextureButton to '_on_button_pressed' method in this script
button_node.connect("button_up", Callable(self, "_on_button_pressed"))
else:
print("TextureButton node not found or accessible.")

func _on_button_pressed():
print("Button pressed!")
# Debug line
print("Button pressed, stopping music and changing scenes!")
audio_player.stop()
get_tree().change_scene_to_file("res://scenes/stages/stage1.tscn")

0 comments on commit 1de4b03

Please sign in to comment.