title: Creating rain animation with physics
body: <p>I'm currently working on an iOS app written in Swift using the SpriteKit game technology. In this game raindrops fall from the top of the screen down to the bottom. When they hit the bottom, which is represented by a <code>physicsBody</code> they should return to their original position at the top of the screen allowing the animation to continue for the lifetime of the game.</p>
  
  <p>Since I only need a few drops I create them like this:</p>
  
  <pre><code>let drop = SKSpriteNode(imageNamed: "drop")
  drop.position = CGPointMake(x,y)
  drop.physicsBody = SKPhysicsBody(rectangleOfSize: drop.size)
  addChild(drop)
  </code></pre>
  
  <p>Then I create the bitmasks:</p>
  
  <pre><code>drop.physicsBody!.categoryBitmask = DropCategory
  bottom.physicsBody!.categoryBitmask = BottomCategory
  drop.physicsBody!.contactTestBitmask = BottomCategory    
  </code></pre>
  
  <p>I add the didBeginContact function and I do get notified when the drop hits the bottom. Then my console displays "hit ground".</p>
  
  <pre><code>func didBeginContact(contact: SKPhysicsContact) {
  
      var firstBody: SKPhysicsBody
      var secondBody: SKPhysicsBody
  
      if contact.bodyA.categoryBitMask &lt; contact.bodyB.categoryBitMask {
          firstBody = contact.bodyA
          secondBody = contact.bodyB
      } else {
          firstBody = contact.bodyB
          secondBody = contact.bodyA
      }
  
      if firstBody.categoryBitMask == BlockCategory &amp;&amp; secondBody.categoryBitMask == GroundCategory {
          println("hit ground")
  
          firstBody.node?.removeFromParent()
          let drop = SKSpriteNode(imageNamed: "drop")
          drop.name = "testNode"
          drop.position = CGPointMake(self.frame.width - self.frame.width/3*2, self.frame.height) // At start Position
          drop.physicsBody = SKPhysicsBody(rectangleOfSize: drop.size)
          drop.physicsBody?.categoryBitMask = BlockCategory
          drop.physicsBody?.contactTestBitMask = GroundCategory
          addChild(drop)
      }
  }
  </code></pre>
  
  <p>However, the position of the drop doesn't change. There is no syntax error, so what's my problem?</p>
  
  <p>If I replace this:</p>
  
  <pre><code>firstBody.node!.position = CGPointMake(x, y)
  </code></pre>
  
  <p>with this:</p>
  
  <pre><code>firstBody.applyImpulse(CGVector)
  </code></pre>
  
  <p>it gives the drop the impulse. How can I make the first option work as well?</p>