SpriteKit PinchGesture SKCameraNode scale

Hello,

I’m currently working on a SpriteKit game in which I have a background layer bigger than my scene with a SKCameraNode. The camera node currently is the size of the scene at a scale of 1. I added a pan gesture to be able to navigate the background layer but require it to stay within the bounds of the background layer.

The problem comes into play when I would like to ability to zoom in closer or further away of background layer but still only pan or zoom within the background layer meaning I don’t want to ever see anything outside of that layer.

I have a couple of ideas but none that I’m thrilled about:

  • Start the camera scale at 0.5, only allow it to zoom out to a scale of 1 and back down to 0.5. This seems pretty limiting to me and not thrilled about the standard zoom level being that close to my bad artwork at first sight.
  • Make a playable area within the full background layer that is panable but not the full layer. You can then zoom out past scale 1.0 showing more background and the adjust the background layer size but you just won’t be able to pan the full layer. Seems like players might get confused.

Ideally I would start the camera scale at 1.0 be able to zoom out to say 2.0 and in to 0.5, pan the entire layer but never see past the background layer into the abyss if you will. Any thoughts or suggestions? Thanks in advance!

1 Like