Search code examples
iosswiftsprite-kitspriteskscene

How to make a view scrollable to view the full scene with sprites with Swift and SpriteKit?


I have a Scene which now fills in the view:

scene.size = skView.bounds.size scene.scaleMode = .AspectFill

I fill in the scene with sprites from bottom to top and in my up they need to go further up - outside the view.

So my scene should have the same width as a view but height should be... around 3000 fixed.

Sprite will fill in the screen and i want to scroll up to be able to view the whole scene.

Would you please give me an advice on how to "construct" that?


Solution

  • Here is a quick road map:

    1. In your game scene "didMoveToView" you want to make a "world" node. Make sure the "world" node is a global variable by declaring it outside of the class. Make that "world" node size as large as the full size needed (e.g., 3000).
    2. Also in "didMoveToView" add a pinch gesture that will eventually allow you to "zoom" that world, using UIPinchGestureRecognizer
    3. Make the function to handle the pinch. Ultimately, the "recognizer.scale" should influence the "world.scale"
    4. All your sprites should be added to the "world" node