Sprite Kit Game Crashes on Game Over on Tvos 9.1 and iOS 9.2

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



Leave a reply



Submit