Regulating the volume of SKAction playSoundFileNamed:

前端 未结 3 1163
心在旅途
心在旅途 2021-02-13 12:05

Is there a way to regulate the volume of sound played via SKAction playSoundFileNamed:waitForCompletion:.

I would like to implement a simple music & sound effects sl

3条回答
  •  渐次进展
    2021-02-13 12:45

    Swift:

    Since iOS 9.0 you can change the volume to your node running another action if you have already runned your audio (remember that this one obviusly cannot work if you have something that run with repeatForever):

    let changeVolumeAction = SKAction.changeVolume(to: 0.3, duration: 0.3)
    node.run(changeVolume)
    

    Or you can create a group and launching your audio with the correct volume:

    let effectAudioAction = SKAction.playSoundFileNamed("electricshockLow.mp3", waitForCompletion: false)
    let changeVolumeAction = SKAction.changeVolume(to: 0.3, duration: 0.3)
    let effectAudioGroup = SKAction.group([effectAudioAction,changeVolumeAction])
    node.run(effectAudioGroup)
    

提交回复
热议问题