我正在使用CCParticleSystemQuad在Cocos2d中创建粒子效果。 现在我想测试每个粒子与CCRect的碰撞。 如何获得粒子引擎中每个粒子的位置,以便我可以这样做?
任何帮助或示例将不胜感激。我已经在网上找了好几个小时,期待找到关于此的教程。我很惊讶我找不到太多,因为我预计与粒子的碰撞是必不可少的;也许我没找对地方:)
答案 0 :(得分:4)
创建CCParticleSystemQuad的子类并覆盖update:method或updateQuadWithParticle:newPosition:method。
@interface MyParticleSystem : CCParticleSystemQuad
@end
@implementation MyParticleSystem
- (void)updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos
{
/* use pos */
[super updateQuadWithParticle:particle newPosition:pos];
}
@end
<强>编辑:强>
您可以将任何数据(位置,颜色等)设置为粒子,如下所示。
@interface MyParticleSystem : CCParticleSystemQuad
@end
@implementation MyParticleSystem
- (void)update:(ccTime)dt
{
/* implement as cocos2d/CCParticleSystem.m -update: */
}
@end
答案 1 :(得分:0)
尝试类似
的内容CCParticleSystemQuad* particle_system = ...;
for(int i = 0; i < particle_system->particleCount; i++)
{
particle_system->particles[idx]->pos; // Here is your position
}
接口的头文件位于:http://www.cocos2d-iphone.org/api-ref/latest-stable/_c_c_particle_system_8h_source.html
警告:因为我不使用Cocos2d或Objective-C,所以请回答这个问题。