Using AVFoundation to Play Audio in an SKAction in SpriteKit

SpriteKit offers two ways to play audio:

  1. SKAction.playSoundFileNamed:waitForCompletion: for playing a sound once
  2. SKAudioNode (since iOS 9): for playing background music in a loop, or do other advanced audio stuff like positional audio (3D spatial audio effects).

The first option is quite unflexible. It just plays the sound once. You cannot change the volume or put any effects on them. SKAudioNode on the other hand offers a lot of cool features via SKActions like changing the playback rate and volume and adding live effects like reverb.

This seems to be a no-brainer. I tried it in my game Fusionate and there was a real bad whistling sound, although I didn’t use any effect or positional audio (just volume changes). So, back to the first option and create a lot of audio files by hand, in order to get the desired effect even for simple things like changing the volume?

No way…

Read More

Lazy Recursive Drill-Down of Tree Structures in Swift 2.1

I really do like the Swift programming language, because of features like multiple return types, nice support for optionals, value types (i.e., structs), enums with associated values, method overloading just with the return type, operator overloading, and many more.

But there are some language decision that are quite alien to me and I want to write them down (and my workarounds to them, which might help you), starting with this post. Perhaps you (yes I mean you 🙂 ) have a better answer for me, then please comment.
Read More