I'm using SKAction to scale a node. After about 2 minutes of game play the node disappears. Basic gameplay is you have to keep touching the node to shrink it otherwise it grows. So you can't play if it's not there. I'm not sure why the node disappears now.
code that creates node :
node.create(mainScreenview, position: CGPoint(x: frame.size.width / 2, y: frame.size.height / 2), size: CGSize(width: 150, height: 150), color: greyColour, name: "Test")
func nodeAction() {
node.runAction(SKAction.scaleBy(10.0, duration: 8.5))
}
Function to compare correct answer
func compareNodes() {
if !nodesToCheck.isEmpty {
let checkThisNode = nodesToCheck[0] as! SKSpriteNode
if checkThisNode.name == node.name {
node.physicsBody = nil
node.removeAllActions()
score += 1
nodesToCheck.removeAll()
changeSizeToSmall()
} else {
gameOver()
}
}
}
func changeSizeToSmall() {
'node.size = CGSize(width: 60, height: 60)'
now SKAction.resizeToWidth(60, height: 60, duration: 1.0))
The error message for this line
node.physicsBody = SKPhysicsBody(circleOfRadius: node.size.width / 2)
Thread1: EXC_BAD_ACCESS (code=, address= 0x0)
and always highlights the node's physicsbody. There is nothing between these lines and the rest of the node code
node.physicsBody?.affectedByGravity = false
node.physicsBody?.categoryBitMask = PhysicsCategory.node.rawValue
node.physicsBody?.contactTestBitMask = PhysicsCategory.bird.rawValue
node.physicsBody?.collisionBitMask = 0
}
The app crashes with that error. The memory usage doesn't change too much during the game but it does increase. I've commented out the SKAction line and I can play the game for as long as I like. So I understand that Shrinking the node and adding a physics body uses a lot of memory but I don't know what to do instead. I've tried removing the node after each time it's called and recreating it again. Tried debugging with the instruments to see what is being dealloc, looking for reference cycles but I'm really not sure what I'm looking for.
What can I do to stop this from happening?
Thanks for any help