Hey coders,
I'm trying to add a particle effect at the contact point of two box2d bodies, but whenever I do the emitter appears in the top left corner of the screen, not at the collision. Currently I can hard code the position of an emitter and I can also get the particle emitter following the touch of my finger, however when I try to pass it a CGPoint created from a b2Vec2 the particles emits from the top right corner (0,0). I'm tracing out the x,y positions from the b2vec2 and getting valid numbers. I've also tried converting these numbers into floats, int, doubles and parseing these in through the cpp() method to see if it makes a difference, but it doesn't seem to. Here's the basic code in the update method where the fixture collision condition has been met:
//if there has been contact on a fixture
//get the body that has collided
b2Body* body1 = contact.fixtureA->GetBody();
//get the b2Vec2 of the body
b2Vec2 position = body1->GetPosition();
//create the particle system
id particleSystem = [[CCParticleSystemQuad alloc] initWithTotalParticles:10];
[particleSystem setEmitterMode: kCCParticleModeRadius];
self.emitter = [CCParticleFireworks node];
[self addChild: emitter z:10];
emitter.texture = [[CCTextureCache sharedTextureCache] addImage: @"stars.png"];
emitter.blendAdditive = YES;
//this is where I convert the b2vec2 position into a CGPoint, and it doesn't work
emitter.position = ccp(position.x,position.y);
emitter.duration = 0.1;
So to surmise, I'm able to get the particle emitter position working when I hard code the location, or when on touchUp interaction. I can also get the collision from the collisionListener and get the correct body from the fixture and get this tracing out the location using:
printf("%4.2f %4.2f\n", position.x, position.y)
I just can't get this number working when feeding it into the particle emitter.position
Any help would be muchly appreciated
Sam