目前在我正在构建的测试应用程序中,我想创建在两个对象发生碰撞时出现的粒子突发。第二个对象将被删除时,主对象将保持可见。在第二个物体(被移除)的位置将是粒子爆发。 我该如何设置? 你能指导我完成在cocos2d中创建这个粒子爆发的步骤吗? 谢谢!
答案 0 :(得分:1)
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:particles
继承了3个发射器的代码:
emitter = [[CCParticleGalaxy alloc] init];
emitter.texture = [[CCTextureCache sharedTextureCache] addImage:@"stars.png"];
emitter.startColor = ccc4FFromccc3B(ccRED);
emitter.endColor = ccc4FFromccc3B(ccGREEN);
emitter.life = 1;
emitter.duration = .5;
emitter2 = [[CCParticleGalaxy alloc] init];
emitter2.texture = [[CCTextureCache sharedTextureCache] addImage:@"stars.png"];
emitter2.startColor = ccc4FFromccc3B(ccRED);
emitter2.endColor = ccc4FFromccc3B(ccGREEN);
emitter2.life = 1;
emitter2.duration = .5;
emitter3 = [[CCParticleGalaxy alloc] init];
emitter3.texture = [[CCTextureCache sharedTextureCache] addImage:@"stars.png"];
emitter3.startColor = ccc4FFromccc3B(ccRED);
emitter3.endColor = ccc4FFromccc3B(ccGREEN);
emitter3.life = 1;
emitter3.duration = .5;
定义为.h
CCParticleGalaxy *emitter;
CCParticleGalaxy *emitter2;
CCParticleGalaxy *emitter3;
CCParticleGalaxy *emitter4;
然后在需要时将其添加到您的图层并设置位置
emitter.position = ccp(sprite.position.x, sprite.position.y);
[self addChild:emitter];
而不是CCParticleGalaxy
您可以将其更改为CCParticleExplosion, CCParticleFire, CCParticleFireworks, CCParticleFire, ect...
只是尝试并找到最适合您的内容