Sprite Kit game crashes on Game Over on tvOS 9.1 and iOS 9.2
The answer I found out was to lower the SKEmitterNode birthrate and particles to emit as this would cause the game to crash.
In the GameScene.swift:
func explosion(intensity: CGFloat) -> SKEmitterNode {
let emitter = SKEmitterNode()
let particleTexture = SKTexture(imageNamed: "spark")
emitter.zPosition = 2
emitter.particleTexture = particleTexture
//LOWER the particleBirthRate and numParticlesToEmit
emitter.particleBirthRate = 50; //4000 * intensity
emitter.numParticlesToEmit = 50; //Int(400 * intensity)
....
}
Once lowered to 50 respectively, then the game wouldn't crash. I don't know why this is happening, but Apple is currently working on this and is considered a bug.
How to detect touches in Sprite Kit tvOS
There is no equivalent to "touching" on tvOS because the user is using either a remote or a game controller.
You will need to design and implement an alternative user interface to provide visual feedback and react to actions on the remote (or game controller).
Apple recommends against using a "cursor" approach so you will need to be creative to find a solution that meets your game's requirements. Given that thumb movements on the remote's touch area are not as reactive vertically as they are horizontally, a cursor is very difficult to control for users.
If your game can have a notion of "Focus", there may be some workable solution. Otherwise, the port to tvOS will be a challenge.
How to remove an sprite when game is over?
OK, so I don't have all that much information about your game to go by, but if you don't want the enemies to keep damaging the player the quick and dirty fix would be to add a guard to the top of your didBeginContact function:
func didBeginContact(contact: SKPhysicsContact) {
guard hits < 3 else {
return
}
let body1 = contact.bodyA.node as! SKSpriteNode
let body2 = contact.bodyB.node as! SKSpriteNode
if ((body1.name == "circuloPrincipal") && (body2.name == "enemigo")) {
colisionPrincipal(body2)
}else {
((body1.name == "enemigo") && (body2.name == "circuloPrincipal"))
colisionPrincipal(body1)
}
}
This should at least prevent anything to get called based on contacts after the required number of hits have occurred. As for cleaning up the sprites, this sounds rather simple (removeFromParent at the appropriate time) but I haven't got a clue about how you handle your game-states so it's hard to comment any further.
Personally I'd trigger it from the update()
function if the required state has happened...
Related Topics
Is There an Object Class in Swift
Avoid Equatable and Hashable Boilerplate, Swift 4.2
Create Skspritenode with an Asset Programmatically
Can't Update Label from Other Class in Swift
Realm Data Insertion Took Over 7Mins for Big Size JSON
Data Structure for Fast Lookup with Multiple Criteria
Using UIviewrepresentable to Wrap Marqueelabel View
Add Value to Variable Inside Closure in Swift
Comparing Time Without Date Swift3
How to Run Terminal Command in Swift from Any Directory
Pass Data from Tableviewcontroller to Another Tableviewcontroller in Swift
How to Create Travelling Wave in Spritekit
How to Create a UIprintpaper to Test UIprintinteractioncontrollerdelegate
Moving from Nsurlconnection to Nsurlsession for Soap Post in Swift
Swift Custom Response Serializer Is Returning Images at Random