Search code examples
swiftsprite-kitskscene

Looking for loading more scene when node goes above Y


I am looking for a way to make my game load more SKScene when my node (ball) goes above certain Y position.

I'm looking for a way to make the loading a little bit like ColorSwitch game where you tap and the ball loads more screen once you hit a certain Y position.


Solution

  • Use SKCameraNode and have it centered on your scene (or wherever it is you want to look at). Check documentation or search here for more help on setting up your camera.

    In update() simply check the position of ball's y value ball!.position.y, if it's past a threshold such as view!.bounds.y, move your camera up by however much camera!.runAction(SKAction.moveBy...)

    If you want to scroll back down, it would be a bit more complicated, but the same principles would apply.

    (note: I have my stuff as Optionals so your code may not have !) https://developer.apple.com/reference/spritekit/skcameranode

    You could also use invisible boxes and collision detection, but that seems more complicated of an approach to me >.>

    If you post some code we can help you get it up and running. Unfortunately, there will be some degree of math involved x[