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 the game starts, it works fine at the beginning (about 60 FPS or less), but then the FPS gradually drops, and the game becomes very slow ... I donβt understand why the FPS falls over time (the number of nodes remains good around 8-10, so they are deleted when they leave the screen). I tested it both on the iOS simulator and on the device itself, any ideas?
I checked the problem is not a memory leak. In addition, I use only one view controller.
The only function that I think could cause this problem is this, but I don't know why:
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)
}