2

I am creating a vertical scrolling game in SpriteKit and I would like to take a screenshot of the entire game scene once the game ends including the parts that have scrolled off screen. So far I am only able to capture the part of the screen that is visible using the following:

    let bounds = self.scene!.view?.bounds
    UIGraphicsBeginImageContextWithOptions(bounds!.size, true, UIScreen.mainScreen().scale)
    self.scene?.view!.drawViewHierarchyInRect(bounds!, afterScreenUpdates: true)
    screenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

Is it possible to get the entire scene?

Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2562126
  • 269
  • 2
  • 12

1 Answers1

4

I was seeing your code and I don't see any problem at all; in fact I tested it (made it a function) and it works perfectly .

func getScreenshot(scene: SKScene) -> UIImage {
    let bounds = self.scene!.view?.bounds
    UIGraphicsBeginImageContextWithOptions(bounds!.size, true, UIScreen.mainScreen().scale)
    self.scene?.view!.drawViewHierarchyInRect(bounds!, afterScreenUpdates: true)
    let screenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return screenshot;
}

I've tested it myself as it is and works; hope it helps :)

Font
  • 41
  • 2