|
|
|
|
Reply From: |
Eidam |
Hello,
my scene:
Node2D
-Button
-AudioStreamPlayer2D
And this is the code attached to the node Node2D:
extends Node2D
func _ready():
$"AudioStreamPlayer2D".play()
func _on_Button_pressed():
$"AudioStreamPlayer2D".stream_paused = !$"AudioStreamPlayer2D".stream_paused
If you need more help, write
I’ve followed your steps.
The current scene:
audio_music (Node2D)
- button (Button)
- music (AudioStreamPlayer2D)
The current GDScript codes attached to the node audio_music:
extends Node2D
func _ready():
$music.play()
func _on_button_pressed():
$music.stream_paused = !$music.stream_paused
But the result remains the same. Whenever I press the button of the music sprite, the music continues. Picture link: Screenshot by Lightshot
Also my original idea for the mute button is this:
My scenes:
menu
CanvasLayer
- btn_play (TextureButton)
- btn_credits (TextureButton)
- btn_quit (TextureButton)
- btn_mute (TextureButton)
audio_player
Node
- ResourcePreloader
- AudioStreamPlayer
Is there a way for the “btn_mute” in scene menu can mute the music in the entire game background, while the “AudioStreamPlayer” is in scene audio_player?
If so, then what are the steps to do that? as well as the required scripts?
Plaz_GD | 2020-05-11 08:36
Hello,
try instead of TexureButton nodes use alone Button with icon. When I add TextureButton, I also can´t pause music… With Button only with icons works it!
Here is my scene: Picture
And here is the code:
extends Node2D
var icon = 1
func _ready():
$"AudioStreamPlayer".play()
func _on_Button_pressed():
$"AudioStreamPlayer".stream_paused = !$"AudioStreamPlayer".stream_paused
if icon == 1:
$"Button1".icon = load("res://stop.png")
icon = 2
else:
$"Button1".icon = load("res://play.png")
icon = 1
This is how it work: Video-without audio
And if you need play/stop music from another scene, do this:
- Add scene with AudioPlayer to Autoload (Project-> Settings-> Autoload-> Open scene with AudioPlayer, name it (something like Music) and allow Singleton
- In other scene´s script write this:
Name_of_Singleton.get_node("AudioStreamPlayer").play()
Regarding your scene in the link below:
https://ctrlv.cz/shots/2020/05/11/nMbz.png
I noticed that you also add scripts to the button node, as well as giving it a signal.
Is the script for the button node the same as the Music (Node2D)?
And what signals should be given to the button node?
Plaz_GD | 2020-05-12 01:12
Hello,
Script added to button is empty, I had this for other things… And I have one signal from Button to script Node2D: func _on_Button_pressed():