title: Detecting collisions in sprite kit
body: <p>I'm trying to make a simple game with sprite kit.
  The basic idea is that there is one player who can jump to avoid blocks.
  But i have a problem I don't know how to make it that when the player hits the block the player disappears and the blood animation starts.
  First of all i don't understand what this code does that I found on apples website.</p>
  
  <pre><code>static const uint32_t blockCategory = 0x1 &lt;&lt;0;
  static const uint32_t  playerCategory = 0x1 &lt;&lt;1;
  </code></pre>
  
  <p>Than i am calling the didBeginContact function and put a NSLOG("did call function") in it.
  But i never receive the output in my debugger.</p>
  
  <p>Here is my _player and _block code:
      -(SKSpriteNode *)character {</p>
  
  <pre><code>_player = [SKSpriteNode spriteNodeWithImageNamed:@"soldier_run1"];
  _player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:_player.size.width /2 -5];
  _player.physicsBody.dynamic = YES;
  _player.physicsBody.usesPreciseCollisionDetection = YES;
  _player.physicsBody.friction = 0;
  _player.physicsBody.categoryBitMask = playerCategory;
  _player.physicsBody.collisionBitMask = blokCategory;
  _player.name = @"player";
  SKAction *animAction = [SKAction animateWithTextures:playerTextures timePerFrame:0.1      resize:YES restore:YES];
  </code></pre>
  
  <p>My _player code:</p>
  
  <pre><code>[_player runAction:[SKAction repeatActionForever:animAction]];
  
  return _player;
  }
  -(SKSpriteNode *)block {
  _blok = [[SKSpriteNode alloc] initWithColor:[SKColor blackColor] size:CGSizeMake(15, 40)];
  
  //physics
  _blok.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_blok.size];
  _blok.physicsBody.dynamic = NO;
  _blok.name = @"block";
  _blok.physicsBody.categoryBitMask = blokCategory;
  _blok.physicsBody.collisionBitMask = playerCategory;
  SKAction *moveBlock = [SKAction sequence:@[
                                            [SKAction moveToX:-20 duration:2] ]];
  [_blok runAction:moveBlock ];
  return _blok;
  }
  </code></pre>
  
  <p>Also i don't really understand what the categoryBitMask and collisionBitMask do.
  After i have that working i would like to make the character disappear from the screen and the blood animation to start, but I have no idea how to let that happen. I think you have to do something like:
         if(_player &amp;&amp; _block didcollide) {
         }
  But I don't know how to do it exactly.</p>