func preloadAudioEffects(effectFileNames:[String]) {
for effect in AudioEffectFiles {
let soundPath = NSBundle.mainBundle().resourcePath!.stringByAppendingPathComponent(effect)
let soundURL = NSURL.fileURLWithPath(soundPath)
var loadError:NSError?
let player = AVAudioPlayer(contentsOfURL: soundURL, error: &loadError)
assert(loadError == nil, "Load sound failed")
player.numberOfLoops = 0
player.prepareToPlay()
audio[effect] = player
}
}
In Swift 3 Beta becomes:
func preloadAudioEffects(effectFileNames:[String]) {
for effect in AudioEffectFiles {
do {
var soundURL = URL.init(fileURLWithPath: Bundle.main().resourcePath!);
try soundURL.appendPathComponent(effect)
let player = try AVAudioPlayer(contentsOf: soundURL)
player.numberOfLoops = 0
player.prepareToPlay()
audio[effect] = player
} catch {
assert(false, "Load sound failed")
}
}
}
I’m a little late to this party but trying to convert the code into SpriteKit and having an issue with matching the tiles and targets. I’ve switched the tiles into SKSpriteNodes with the letters as SKLabelNodes added as children. Using the TileDragDelegateProtocol I’m not detecting any contact likely because I haven’t figured out how to rewrite the extension comparing the nodes. I’ve also tried using SKPhysicsContactDelegate (in duplicate project), I can detect contact but it’s between any tile and any target, again likely issue with comparison of subclass properties. Any recommendation on which path I should pursue?
This will tell you about collision as well as other useful SpriteKit things.
In the contact delegate, you can test the name of the sprite, or the class (if let x = y as? ClassName etc). So you can test to see what objects are contacted.
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]