2

Ok so currently I have a camera coded into my project. I added my background to the game and it doesn't move currently. However, I want to add more things that aren't affected by the camera such as a ground.

Here is my current code:

 background.position = CGPoint.zero 
 background.zPosition = -10 
 camera.addChild(background)

The code I have above only allows me to center the item but will not let me put it at a certain point I want. How can I do this?

Josh Schlabach
  • 401
  • 5
  • 17
  • 1
    Adding the ground as a child of the camera will not result in it being stationary. – Wes Nov 22 '16 at 23:55
  • It does actually work, but I can only have it centered.. – Josh Schlabach Nov 23 '16 at 19:54
  • @JoshSchlabach It's centered because you're setting its position to (0,0), which is the centre of the screen if your `anchorPoint` is (0.5,0.5) – Nik Nov 24 '16 at 00:57

2 Answers2

2

If I understand your question, you would like some nodes to stick on screen all the time (like some score counter or timer)?

If you want to achieve this, just add child node to camera and not to main scene, and node will always follow your camera.

Do it like:

yourCameraNode.addChild(scoreCounter)
MOzeb
  • 423
  • 1
  • 6
  • 14
0

You have to add the other children to the scene and not the camera. If for your in your scene, you can just do self.addChild(background)

DreamerNo56
  • 213
  • 1
  • 8
  • Well what is it that you mean when you say "You dont want it affected by the camera?". If its not a child of the camera it will of course, not move with the camera. Please be more specific with your question – DreamerNo56 Nov 23 '16 at 20:22
  • Exactly, that's what I am saying, but it doesn't work when I add it to the scene. – Josh Schlabach Nov 23 '16 at 20:28