Playing a secondary theme in Cocos2D
Cocos2D offers CocosDenshion, an easy to use framework to work with audio.
CocosDenshion allows you to play a background music and then some effects on top of that. This is clearly aimed at games and it usually works really well. The difference between background music and effects is summarized as follows:
- background music is thought of as potentially of long duration, so it is handled as a long audio stream;
- background music is thought of as continuous, so it is played in exclusive mode;
- effects are thought of as smaller in size, so they are loaded into memory entirely;
- effects are by their definition itself aimed at being played many times, so they are cached into memory for reuse;
- effect can be mixed to background music, so they do not “steal” the audio subsystem.
This works well until your effects are pretty small in size, otherwise your memory requirements will quickly grow. On iOS this is a no-no, since your app has very little memory to run with. Another case when CocosDenshion falls short is when you want your effects to be played continuously in a loop.
Say, for example, that you have a main background theme that is played in a loop, and then a secondary theme that you would like to be also played in a loop when your character enters some given state.
Suche scenario led me to create a small category on CocosDenshion SimpleAudioManager which defines four methods:
-(void) playForegroundMusic:(NSString*)filePath loop:(BOOL)loop;
-(void) stopForegroundMusic;
-(void) pauseForegroundMusic;
-(void) resumeForegroundMusic;
playForegroundMusic will simply play your secondary theme on top of your background music without claiming exclusive access to the audio subsystem. You can find it on my github together with the rest of my Cocos2D snippets.
iOS6: dynamic autorotation
One of the most intrusive changes brought by iOS6 is the way autorotation is handled in UIViewControllers. If you have an autorotating app for iOS5, you will need to change it to correctly support autorotation under iOS6. If you develop an app which is supposed to run both on iOS5 and iOS6, then you will have to handle autorotation in the old as well as the new way.
Hitchhiker's guide to MKStoreKit
In-App Purchase is one of those great feature of the iOS ecosystem that I wish were easier to understand and implement in my apps. In the end it is just a machinery that will not really add value to my apps, and it would be great if the Apple motto “it just works” could be applied to StoreKit as well.
What's new in iOS 7 User Interface – Part 2: Deference
In a previous post, I began describing what changes the introduction of iOS 7 brought to iOS UI/UX dimension. In that post, I listed 4 main principles shaping the idea of iOS flat-UI:
How Instruments can be used to fix a graphics performance issue
Lately, I have been investigating an issue a customer of mine’s app showed.