Search code examples
objective-ccocos2d-iphone

NSMutable array count not changing after removed child


GMSprite *bulletMove;
int bulletCount = [bullets count];

for(int i = 0; i < bulletCount; i++)
{        
    if(bulletMove.position.x > 500)
    {
        [self removeChild:[bullets objectAtIndex:i] cleanup:YES];
    }
}

How do i remove the child from the array and also the object in the array so that bulletCount goes down an integer and adjusts the array to the removed object


Solution

  • Use below code:

    [bullets removeObjectAtIndex:i];
    

    Get bullet object from bulet array and use below code.

    [bullet removeFromParentAndCleanup:YES];