Most convenient way to play sound in iOS games? - iphone

I'm making a game and would like to have a background loop of game music and on top of it have two different channels of sound effects. I would like to control the volume of these channels. I looked at fmod, but it was out of my budget. Now instead I'm looking at the MixerHostAudio example provided by Apple. It's a clear example, but a bit long-winded being 1000+ lines just for playing two sounds, so I'm wondering if I should be doing something else instead.
My ideal API would look something like this:
SoundSystem *sounds = [SoundSystem soundSystemWithLoop:#"koto.mp3"];
[sounds play:#"chimes.mp3" channel:1 looping:YES volume:0.0];
[sounds fadeTo:1.0 channel:1 delay:0.5];
[sounds play:#"buddha_bell.mp3" channel:2];

You can use AVAudioPlayer for the background loop and Finch for SFX. Both are easy to work with. You’d have to write the channel volume control above Finch yourself, but that’s not hard either, being just an array of sounds with a common volume control.

CocosDenshion Sound Engine does everything you want.
It is trivial to use once you get it in your project.
CocosDenshion is the sound part of Cocos2D.
I just personally do not care for Cocos2D (although, of course, many people love it and use it).
However CocosDenshion for sound does everything you want with no problems. Yes it does both BG loops and SFX. It manages all memory, etc.
It is easy to use CocosDenshion (just copy a few files to your project) -- no problem. (You do not have to fool with the whole Cocos2D situation...you install simply only the Denshion section.)
Hope it helps!

I'm using SoundMaster engine. It's much better than CocosDension Sound Engine, because of ARC support, memory management and many other features like fade in/out, or relative volumes for effects.

Related

Which has better performance, symbols in the library or exported images of those symbols?

I recently chose to switch to a method where my library is totally empty and I embed every image/animation/sound that I need via the Embed tag because it would make my life easier. Having a lot of symbols in my library causes CS5 to run extremely slowly and it was really annoying me.
This was totally fine for making games for computers but I'm currently working on my first iPhone game and I'm noticing that the game starts lagging after a few seconds of play. It's not even a complex game but it does have a lot of images with transparency. So I'm wondering if it would run faster if I forget about the empty library method. I don't really know how that would affect performance but this is the first time that I have to worry about performance. But I am aware of other things that affect performance like transparency and object pooling (just read about this one).
Also the exact same game runs worse on an iPad even though it's a more powerful device?
Having images in your library means that Flash will compress them when it exports the SWF/SWC. This may or may not be desirable.
Using the [Embed] tag means that you can compress them yourself in something like Photoshop and have complete control over the output.
You say that your "game starts lagging after a few seconds of play". This seems to be a memory/design problem rather than whether or not your images are embedded through code or as library symbols. Do some profiling to see where you're spending most of your time, and to check that you don't have a memory leak.
Both using the library and the [Embed] metatags influence performance of your IDE, but they are evaluated at compile time and will produce just about the same byte code.
The performance of your game at runtime is an entirely different issue, though you might be able to get good results by rethinking which images to embed as bitmaps and which to use as vector sprites, how to organize larger images (e.g. creating one basic player sprite and adding individual looks by composition, instead of making each player variation a full sized animation) and trying to reduce the use of transparency and alpha masks.
There are many good articles about improving ActionScript performance both on the AVM2 and on iOS devices. Try searching for "ActionScript optimization runtime" - it should yield plenty of results.

Starting a Sound at a specified position with CocosDenshion?

It's possible to do stuff like:
Reproduce a sound at a specified starting position
Reproduce a sound for a certain ammount of time
Using CocosDenshion ?
If so, how ?.
If not...i have any alternatives, like a different sound engine or a certain class in the SDK that would allow me to do both things ?
You can play positional audio with CocosDenshion. See this tutorial for example.
Of course you can also loop sounds, if that's what you meant by question #2. You can always schedule a timer and stop or (better) fade out the sound after a specified amount of time. Programming the timer is of course up to you.
As for an alternative I can highly recommend ObjectAL. It does everything CocosDenshion does and a few things more, plus its well documented and comes with an excellent demo app with examples for playing positional audio, looping sounds, using stereo channels with panning and fading sounds.
If you don't want to fumble with including a static library in your project have a look at Kobold2D, it comes with ObjectAL (and Cocos2D) already setup and ready to use.

Does my *Entire* game have to be remade, to use Cocos2D?

I have been making my game in a pretty conventional manner. I just created a new window based application and have built off of that using my own images, table views, etc. Now I am about to begin programming the gameplay, and I just recently discovered Cocos2D. My question is this: In order to use Cocos2D for the actual gameplay (Which would take place in a single view) do I need to recreate my app from scratch? Or can I just make the one view using Cocos2D?
You could go down the mix-and-match route, but it would likely drive you insane.
If you want to embrace Cocos2D, you will likely be better off moving to it fully. More likely than not the time invested will be yield improvements in your existing code that you'll find surprising (certainly, I've found that rewriting something pretty much always yields a better solution in fewer lines of code).
You do not want to keep using the standard SDK in your game, if you're going to use Cocos2D for the game view (which you totally should).
Re-do the entire app in Cocos2D -- you'll have way more possibilities to make your game menus awesome and much less headaches; both while developing and while maintaining your game.

Timeline based animations on the iPhone/iPad

How would you go about creating a timeline animation for an iPhone or iPad application? I'm looking for something like a timeline animation in Flash. I don't need a technical explanation on how to program it, though.
So here are some general questions:
- I read something about UIView for PNG sequences, but aren't these kind of animations resource intensive? And what about filesize? PNG can't be compressed like jpeg.
- What about vector-like animations? These would save a lot of kb's.
- Are there animation frameworks like TweenLite/TweenMax/Tweener/... (some well known frameworks for animations in ActionScript) ?
- Any good references on how to make animations (like Text animations, ...)
Thanks in advance.
Bart
Apple pretty much spells it out in Getting Started with Graphics and animation.
In general just stick with the highest possible API, and test to see if it's going to meet your needs or not. Moving around a UIView or UILabel (text) as in a Timeline Animation not only takes just a couple of lines of code but it will probably perform just fine.
This only just came out, but have you heard of Hirameki?
It's a flash animation parser that lets you drop SWF animations directly into Xcode projects for iPhone. A demonstration and beta sign up is here http://www.flash-on-iphone.com

Any good iPhone sound manager framework?

I'm developing an iPhone game and currently using AVAudioPlayer for playing background music and sounds.
From what I've been reading, I'm not sure if that's the best way, but other alternatives seem to be overly complex.
Is there any good open source framework that works on the iPhone and I can integrate? I only need to control the volume and trigger sounds based on different game events.
Clarification: AVAudioPlayer meets my needs for playing one sound, but I'd like a wrapper class where I can set up multiple sounds and have them play based on some key.
It's not clear from your message whether AVAudioPlayer meets your needs. On the one hand you didn't mention any shortcomings you've encountered, but on the other hand your asking for alternatives suggests there are some.
If AVAudioPlayer does meet your needs, why make life difficult?
If AVAudioPlayer does not meet your needs, you need to explain what else you need before anyone can do anything but guess at what you're looking for.
The sound engine that Apple includes in their moon lander sample code application allows for playing multiple sounds at a time and everything.
You can use AVAudioPlayer. Each of your sounds will be a different instance of that class. Hold onto all the sounds (players) in a dictionary or an array. You can then easily play each by indexing off the array or getting with a key from the dict. Each sound can have it's own volume, or you can iterate the array or dict to set all volumes to whatever levels you like.
Couple of points to remember: 1. if you have to play the sounds in a timely manner, then use the -prepareToPlay method right after loading from file. 2. if you stop a sound, then -prepareToPlay is undone. If you pause a sound, then before you play it again, make sure you set the currentTime property to 0 so the sound starts from the beginning.