[SOLVED]Correct Method To Load Sound Effect, Set its Volume, Then Play It - All In Script Code?

JeZxLeeJeZxLee Posts: 67Member
edited August 1 in Audio

Hi,

We got music working, but are confused about sound effects.
What is the correct method to load sound effects, set their volume, and then play them all in script code?

Let us know, thanks!

Jesse
www.FallenAngelSoftware.com

Comments

  • JeZxLeeJeZxLee Posts: 67Member

    Hi,

    We got the sound effect playing now, but it repeats?
    How to disable repeat of playing sound effect?

    Jesse

    # "AudioCore.gd"
    extends Node
    
    
    var MusicVolume
    var EffectsVolume
    
    
    func _ready():
    
        MusicVolume = 1.0
        EffectsVolume = 1.0
    
        var music_player = AudioStreamPlayer.new()
        music_player.stream = load("res://media/music/TitleBGM.ogg")
        add_child(music_player)
        music_player.set_volume_db(linear2db(MusicVolume))
        music_player.play()
    
        var effect_player = AudioStreamPlayer.new()
        effect_player.stream = load("res://media/sound/Explosion.ogg")
        add_child(effect_player)
        effect_player.set_volume_db(linear2db(MusicVolume))
        effect_player.play() # Plays, but how to disable repeat?
    
    
        pass
    
    
    func _process(delta):
    
    
        pass
    
  • JeZxLeeJeZxLee Posts: 67Member

    effect_player.stream.set_loop(false)

  • SIsilicon28SIsilicon28 Posts: 748Moderator
    edited July 26

    *redacted*

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file