cocos2d-iphonespritebuilder

Positionning particle in node


Using cocos2d, I'm trying to replace a sprite (item in my code) with a particle system. This code is placed in my board class. This one works:

    // Draw the particles 
    CCParticleSystem *particles = [[CCParticleSystem alloc] initWithDictionary:_popParticles];
    particles.position = ccpSub(item.position,ccp(160,160));
    particles.autoRemoveOnFinish = TRUE;
    [self addChild:particles];

This one doesn't:

    // Draw the particles 
    CCParticleSystem *particles = [[CCParticleSystem alloc] initWithDictionary:_popParticles];
    particles.position = item.position;
    particles.autoRemoveOnFinish = TRUE;
    [self addChild:particles];

I tried player with this but without success:

    particles.positionType = CCPositionTypeMake(CCPositionUnitUIPoints, CCPositionUnitUIPoints, CCPositionReferenceCornerBottomLeft);

My board is a 320x320 points CCSprite with anchor point set at 0.5, 0.5

When I log my item.position value, I get something relative to the bottom left corner of my board (from 30,30 to 290,290)

Is using ccpSub the correct way ?

Hierarchy of my objects in Spritebuilder


Solution

  • When you destroy a node you also destroy all of it's children nodes, you said you add your particle to 'item' then you destroy that 'item', which means you have no particle anymore.