I have a game using Sprite-Kit and Swift where I generate random circles falling from the top of the screen to the bottom of the screen.
When launching the game, it runs perfectly fine at the beginning (at around 60 FPS or less) but then the FPS drops gradually and the game becomes extremely slow... I don't understand why the FPS drops with time (the number of nodes stays good at around 8-10, so they get removed when they go off the screen) - I tested it on both the iOS Simulator and an actual device, any ideas?
I have checked, the problem isn't coming from a memory leak. Also, I am using only one view controller.
The only function that I think could cause this issue is this one, but I don't know why:
/* Function to generate single random circle */
func generateCircle() -> Void {
let circleSize:CGFloat = CGFloat(arc4random_uniform(40) + 3)
let xPosition:CGFloat = CGFloat(arc4random_uniform(UInt32(size.width)))
var randomCircle = SKShapeNode(circleOfRadius: circleSize)
randomCircle.strokeColor = SKColor.redColor()
randomCircle.fillColor = SKColor.redColor()
randomCircle.physicsBody = SKPhysicsBody(circleOfRadius: circleSize)
randomCircle.physicsBody?.dynamic = false
randomCircle.position = CGPoint(x: xPosition, y: size.height + circleSize*2)
randomCircle.physicsBody?.dynamic = true
randomCircle.physicsBody?.categoryBitMask = randomCirclesGroup
addChild(randomCircle)
}