0 votes

I have this code, where I have embedded the sound to play when the button is pressed which also connected to the scene transition. Therefore, the order of my transition would be Enter button pressed, and then the sound played, and then the transition.

func input(event):
if event.is
actionpressed("NextLevelEat"):
$NextLevelSound.play()
if get
overlappingbodies().size() > 0:
visible = false
change
tonextlevel()

This is the code I have, but when the scene is played the sound is very short instead of the length of the audio it should be.

in Engine by (72 points)

2 Answers

0 votes
Best answer

The scene changes before the sound has finished playing. Try making the script wait until the sound finishes playing. (Note: I don't know if this is how the code is structured.)

func input(event):
    if event.is_action_pressed("NextLevelEat"):
       $NextLevelSound.play()
        # Stop the script until the sound has completed playing.
        yield($NextLevelSound, "finished")
   if get_overlapping_bodies().size() > 0:
       visible = false
   change_to_next_level()

Please note that the "finished" signal won't be emitted if the sound loops.

by (2,394 points)
selected by
0 votes

You are not checking if the sound has finished before you change the level I suspect that is the issue.

you can use

if $newtlevelsound.is_playing() == false:

before you run the change to next level that should work although without seeing the rest of your code its difficult to say for sure.

by (1,377 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.