when hover TextureButton play sound?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By huahuapro

how to:
when you hover a TextureButton, then play a sound.


:bust_in_silhouette: Reply From: johnygames

Follow these steps:

  1. Create a new script if you don’t have one already.
  2. Go to the Node panel of the TextureButton and connect the mouse_entered signal to your script
  3. Create a new AudioStreamPlayer node
  4. In your script write this code:
extends Node2D

onready var audioS = $AudioStreamPlayer # or whatever you named the AudioStreamPlayer node

func _on_TextureButton_mouse_entered():
  1. Go to your AudioStreamPlayer’s properties and choose a sound file for it to play under Stream–> Load

  2. Go to your sound file’s Import tab and uncheck the Loop property so that it doesn’t loop when you play it.

Voila! Is this helpful? Please upvote and select this answer if it helped you.

it work!


huahuapro | 2020-03-11 10:47

Hey there. I’m relatively new to the game creator space, so I’m a big noob here.
I’ve followed all your steps as well, and so far so good.

However, when I launch the game and I hover over my button, it crashes and gives the following error of:

ERROR: Node not found: menu/AudioStreamPlayer At:

Since I have the StreamPlayer in another path, I’ve set it to that said path.
I’ve been trying to fix it myself as I don’t really like asking for help, you learn more by experimenting, but this is really heating my brains, lol.

D_Zenith | 2020-04-28 14:55

Could you provide a bit more info? What is your Scene tree like? What did you set the path to? How is your code different from the snippet above?

I sounds like a path error where the engine cannot find the file it is looking for. You must have made a mistake with the path, but I cannot be sure unless you provide some more info.

johnygames | 2020-04-30 16:51

Heya, no worries now, figured it out myself. It had to do with a wrong path like you said.

Thank you for the reply anyways! Cheers!

D_Zenith | 2020-04-30 17:25