开发者

How to get particle position in Cocos2d (iphone)

I am using CCParticleSystemQuad to create a particle effect in Cocos2d. Now I would like to test each particle for collisions with a CCRect. How do I get the postio开发者_JAVA百科ns of each particle in the particle engine so I can do this?

Any help or examples would be appreciated. I've looked for hours on the net expecting to find tutorials on this. I am surprised I can't find much as I would expect collisions with particles to be essential; Perhaps I wasn't looking in the right place :)


Create a subclass of CCParticleSystemQuad and override update: method or updateQuadWithParticle:newPosition: method.

@interface MyParticleSystem : CCParticleSystemQuad
@end

@implementation MyParticleSystem
- (void)updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos
{
    /* use pos */
    [super updateQuadWithParticle:particle newPosition:pos];
}
@end

EDITED:

You can set any data (position, color, or so on) to the particles as the following.

@interface MyParticleSystem : CCParticleSystemQuad
@end

@implementation MyParticleSystem
- (void)update:(ccTime)dt
{
    /* implement as cocos2d/CCParticleSystem.m -update: */
}
@end


Try something like

CCParticleSystemQuad* particle_system = ...;
for(int i = 0; i < particle_system->particleCount; i++)
{
    particle_system->particles[idx]->pos; // Here is your position
}

The header file for the interface is here: http://www.cocos2d-iphone.org/api-ref/latest-stable/_c_c_particle_system_8h_source.html

Warning: Take this answer with a grain of salt as I don't use Cocos2d, or Objective-C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜