Skip to content

ThiagoAM/GameAudioPlayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GameAudioPlayer (Swift 5.0)

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!

Example (easier way)

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)     
    }
    
}

Example (better performance way)

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)        
    }
    
}

License

Game Audio Player project is licensed under MIT License (MIT-License or https://opensource.org/licenses/MIT)

About

A simple SpriteKit audio player with customizable performance and absolutely no memory leaks!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages