Reputation: 83
My Sprite Kit game has trouble reacting to banner notifications. When the user gets an alert notification, the game pauses as intended thanks to applicationWillResignActive
, which isn't called with banner notifications. When there is a banner notification, the projectiles in the game go straight through walls instead of being removed from their parent after making contact with the (thick) wall.
I've searched, but I can't find any function that I can use to pause the game when the user gets a banner notification. Anyone know of a function I can use?
Upvotes: 1
Views: 420
Reputation: 10664
You have 2 options basically
Pause the SKView in your ViewController
self.view?.paused = true
The problem here is that it will pause everything which makes it a bit trickier to add pauseMenus or other nodes after.
The better way is to create a worldNode (global)
let worldNode = SKNode()
add it to the scene
addChild(worldNode)
than add all your sprites that you need paused to that node
worldNode.addChild(yourSprite)
and than finally when you want to pause the game you call
worldNode.paused = true
self.physicsWorld.speed = 0 // call this as well when paused and reset to 1 when resuming
This way you can still add pauseMenu nodes/sprites, labels and so on while your game is paused.
To do this when a notification is received I believe you need to use the delegates methods in a your app delegate such as this one
application:didReceiveLocalNotification
You can read more here
Upvotes: 3