Game Development Reference
In-Depth Information
For playing sound effects, the SimpleAudioEngine class usually suffices. To use
it, you must import the SimpleAudioEngine.h header file in every file you're us-
ing the SimpleAudioEngine class because cocos2d doesn't treat the CocosDensh-
ion audio engine as an integral part of the engine.
As you play the game with the new particle effects, you may notice that the first time
one of these effects displays, the game play stops for a short moment. That's because
cocos2d is loading the particle effect's texture—a rather slow process, whether the tex-
ture is embedded into the plist, as in this case, or provided as a separate texture. To
avoid that, I'm preloading the particle effects and sound files in the GameLayer:
-(id) init
{
if ((self = [super init]))
{
. . .
// To preload the textures, play each effect once off-screen
[CCParticleSystemQuad particleWithFile:@"fx-explosion.plist"];
[CCParticleSystemQuad particleWithFile:@"fx-explosion2.plist"];
// Preload sound effects
[[SimpleAudioEngine sharedEngine] preloadEffect:@"explo1.wav"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"explo2.wav"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"shoot1.wav"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"shoot2.wav"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"hit1.wav"];
}
return self;
}
The init method now creates each particle system for each particle effect once, but it
doesn't add it as child anywhere. This causes the texture to be cached by cocos2d. If
you chose not to embed the texture inside the particle effect plist file, you can preload
the particle effect textures simply by calling the CCTextureCache addImage
method:
Search Nedrilad ::




Custom Search