Sprite Kit & playing sound leads to app termination

The problem is AVAudioSession can’t be active while the app enters background. This isn’t immediately obvious because Sprite Kit makes no mention that it uses AVAudioSession internally. The fix is quite simple, and also applies to ObjectAL => set the AVAudioSession to inactive while the app is in background, and reactivate the audio session when … Read more

How does collisionBitMask work? Swift/SpriteKit

You can’t get desired behaviour because you haven’t set category, contact and collision bit masks properly. Here is an example on how you can set this to work: greenBall.physicsBody?.categoryBitMask = GreenBallCategory //Category is GreenBall greenBall.physicsBody?.contactTestBitMask = RedBarCategory | WallCategory //Contact will be detected when GreenBall make a contact with RedBar or a Wall (assuming that … Read more

Sprite kit and colorWithPatternImage

iOS working code: CGRect textureSize = CGRectMake(0, 0, 488, 650); CGImageRef backgroundCGImage = [UIImage imageNamed:@”background.png”].CGImage; UIGraphicsBeginImageContext(self.level.worldSize); // use WithOptions to set scale for retina display CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawTiledImage(context, textureSize, backgroundCGImage); UIImage *tiledBackground = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); SKTexture *backgroundTexture = [SKTexture textureWithCGImage:tiledBackground.CGImage]; SKSpriteNode *backgroundNode = [SKSpriteNode spriteNodeWithTexture:backgroundTexture]; [self addChild:backgroundNode];

Screenshot showing up blank – Swift

update: Xcode 8.2.1 • Swift 3.0.2 You need to add the import statement and this extension to your game scene: import UIKit extension UIView { var snapshot: UIImage? { UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0) defer { UIGraphicsEndImageContext() } drawHierarchy(in: bounds, afterScreenUpdates: true) return UIGraphicsGetImageFromCurrentImageContext() } } let myImage = view?.snapshot

How do I present a UIViewController from SKScene?

You’re creating a new view controller but never presenting it: SpriteViewController *viewController = [SpriteViewController alloc]; I’m assuming that SpriteViewController is what presents your SpriteMyScene, and you’d like to hand control back to the presenting SpriteViewController. You need to keep a reference to SpriteViewController in your SpriteMyScene subclass, and then access that reference when you call … Read more

SpriteKit’s SKPhysicsBody with polygon helper tool

I am looking for the exact same thing, as it turn out I have done a small web app for this purpose. SKPhysicsBody Path Generator as action in example: Update 2015-02-13: script <!DOCTYPE html> <html> <head> <meta charset=”UTF-8″> <title>SpriteKit Tools – SKPhysicsBody Path Generator</title> <link rel=”stylesheet” href=”https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css”> <style> /* disable responsive */ .container { max-width: … Read more