Bad render CCSprite with cocos2d and SpriteBuilder

21 Views Asked by At

when I add CCSprite to CCPhysicalNode in a different thread than main, this CCSprite render in a black square like see in the image.

It's strange because the other CCSprite like Enemy or Hero are render ok like see in the image (Enemy is the colour Green and Hero is the colour red)

// in the method didLoadFromCCB Main Scene 
-(void)didLoadFromCCB
{
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
                   ,^(void){
         [self buildGround];
    });
}

// implements method buildGround 
-(void)buildGround
{
    while (i < WORLD_SIZE)
    {
        Ground *ground = (Ground*)[CCBReader load:[NSString stringWithFormat:@"nameGround%d",i]];
        ground.physicsBody.collisionType = @"ground";
        ground.position = ccp(lastPosition, 0);
        [_ground addChild:ground];

        Enemy *enemy = (Enemy*)[CCBReader load:@"Enemy"];
        enemy.position = ccp(positionX , positionY);
        enemy.physicsBody.collisionType = @"enemy";
        [_ground addChild:enemy];
        i++;
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [_physicsNode addChild:_ground];
    });
}

enter image description here

1

There are 1 best solutions below

0
kakashy On

I solve my problem, the error was caused because the directory is not "Smart Sprite Sheet" in SpriteBuilder.

The solution was:

  1. In SpriteBuilder click right over directory where save images for sprite
  2. Click in sub menu "Make Smart Sprite Sheet"
  3. Save, publish and thats all

enter image description here