Creating a sprite during didBeginContact

I worked on some SpriteKit tutorials. I understand the whole collision problem and checked with NSLog that a collision is being recorded between my two objects. However, for some really strange reason, my sprite is not created (or rather shown) when it was made during didBeginContact.

- (void)didBeginContact:(SKPhysicsContact *)contact
{
    uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
     if (collision == (CNPhysicsCategoryPlayer | CNPhysicsCategoryRock))
     {
         NSLog(@"ouch");
         SKSpriteNode *bigOuch = [SKSpriteNode spriteNodeWithImageNamed:@"star"];
         bigOuch.position = CGPointMake(200, 200);
         [self addChild:bigOuch];
     }
}

I get an ouch log message, but no sprite appears.

I tried the same thing (creating a sprite) in other parts of my program and had no problems. What am I doing wrong?

+4
source share
1 answer

. SKSpriteNode , . , , didBeginContact. . , . , .

+2

Source: https://habr.com/ru/post/1536160/


All Articles