title: SpriteKit static HUD with camera on player
body: <p>My issue is the HUD isn't staying in the same position but moving with the camera also.</p>
  
  <p>I'm trying to create a version of Sokoban using <a href="https://github.com/kennycason/swift_boxxle" rel="nofollow noreferrer">swift_boxxle</a> code found on Github,</p>
  
  <p>I've added a new SKNode called mazeWorld, a camera node and a HUD node.</p>
  
  <pre><code>var mazeWorld: SKNode?
  let cam = SKCameraNode()
  var HUD: SKNode?
  </code></pre>
  
  <p>In my didMoveToView I'm adding both the mazeWorld and the HUD to the scene.</p>
  
  <pre><code>override func didMoveToView(view: SKView) {
      HUD = SKNode()
      addChild(HUD!)
  
      mazeWorld = SKNode()
      addChild(mazeWorld!)
  
      self.camera = cam
      ...
      initMenu()
  }
  </code></pre>
  
  <p>I'm using the update function to set the camera position to the player position:</p>
  
  <pre><code>override func update(currentTime: CFTimeInterval) {
      cam.position = player.sprite.position
  }
  </code></pre>
  
  <p>I've got another function to setup the menu</p>
  
  <pre><code>func initMenu() {
      menuReset.text = "[reset]"
      menuReset.fontSize = 20
      menuReset.fontColor = SKColor.whiteColor()
      menuReset.position = CGPoint(x: self.size.width/2, y: self.size.height/2 - 20)
      menuReset.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left;
      ...
      HUD!.addChild(menuMain)
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kwYMV.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kwYMV.gif" alt="Sample moves"></a></p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I added the following:</p>
  
  <pre><code>    let label = UILabel(frame: CGRectMake(0, 0, 200, 21))
      label.textAlignment = NSTextAlignment.Center
      label.text = "I'am a test label"
      label.textColor = UIColor.whiteColor()
      self.view!.addSubview(label)
  </code></pre>
  
  <p>With <a href="https://stackoverflow.com/a/8508535/2895831">SO Answer</a></p>
  
  <pre><code>    var frame: CGRect = label.frame
      //align on top right
      let xPosition: CGFloat = CGRectGetWidth(view.frame) - CGRectGetWidth(frame)
      frame.origin = CGPointMake(ceil(xPosition), 0.0)
      label.frame = frame
      //autoresizing so it stays at top right (flexible left and flexible bottom margin)
      view.autoresizingMask = [.FlexibleLeftMargin, .FlexibleBottomMargin]    
  </code></pre>