How to use (easier way):
• Add the GameAudioPlayer.swift
file to your project
• Create a GameAudioPlayer
instance
• Play your sounds with the playSoundFileNamed
method
• That's it!
How to use (better performance way):
• Add the GameAudioPlayer.swift
file to your project
• Create a GameAudioPlayer
instance
• Load your sounds with the prepareSound
or prepareSounds
method
• Set the maximum number of times a certain sound can play at the same time with the setMaxConcurrentPlayback
method
• Disable cached sounds with the disableCachedSounds
method for even better performance (optional)
• Play your sounds with the playPreparedSound
method
• That's it!
class TestGameScene : SKScene {
// Declaring the GameAudioPlayer Instance:
var audioPlayer : GameAudioPlayer?
override init() {
super.init()
// Initializing GameAudioPlayer's Instance:
audioPlayer = GameAudioPlayer(scene: self)
// Playing a sound:
audioPlayer?.playSoundFileNamed("explosion1", duration: 2, doesLoop: false)
}
}
class TestGameScene : SKScene {
// Declaring the GameAudioPlayer Instance:
var audioPlayer : GameAudioPlayer?
override init() {
super.init()
// Initializing GameAudioPlayer's Instance:
audioPlayer = GameAudioPlayer(scene: self)
// Preparing the sounds:
let soundNames = ["explosion1", "backgroundMusic3", "powerUpSound"]
audioPlayer?.prepareSounds(soundFileNames: soundNames)
// Playing a sound:
audioPlayer?.playPreparedSound("explosion1", duration: 2, doesLoop: false)
}
}
Game Audio Player project is licensed under MIT License (MIT-License or https://opensource.org/licenses/MIT)