Cocos2d SimpleAudioEngine Example

Sound effect always is very important part of Game, I used to use other library that playing sound effect on iPhone App, but it totally make the size of the game bigger and slower. Now, I have move my game design from Cocoa To Cocos2d and it's include a few audio playing library. since I just need a background music and some sound effect, so I have choose SimpleAudioEngine.

Steps for playing background music
1. add your sound effect file to project (e.g. BG.mp3)
2. add header file to AppDelegate
#import "SimpleAudioEngine.h"
3. make sure you have add "SimpleAudioEngine.h" and "SimpleAudioEngine.m" from cocos2d

because I want to play the backgrund music after the app have finish loading. so I have make following change for applicationDidFinishLaunching

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BG.mp3"];

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
...
}

and Now, if we want to play a sound effect when user tap the button, we should preload the sound effect file on app delegate first, or any function before you play it.
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BG.mp3"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"tapBtn.mp3"];\

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
...
}

and play it when you need it

-(void)tapButton:(id)sender
{
[audioEngine playEffect:@"tapBtn.mp3"];
}

Mahjong Match 2


Mahjong Match 2, the new match game from Leung's work!


There is maximum have 200 pairs of Mahjong in different place and layer every time you start the game. The player will pairs by touching them.


If you find there is no Mahjong can be pair, you can shuffle the mahjong anytime. and there is a continue function added to Mahjong Match 2. The game have well prepare for iPhone and iPod Touch. Enjoy the relax and fun game.