UPDATE
More info here: Poor performance with SKShapeNode in Sprite Kit
I'm learning the new Swift language. To challenge myself, I'm trying to build a Curve Fever clone with SpriteKit on iOS 8. I'm using CGPath to draw a path behind the player (a circle).
var linePath : CGMutablePathRef = CGPathCreateMutable()
var line : SKShapedNode!
override func update(currentTime: CFTimeInterval) {
// Adjust player's location on the field based on touches left or right
...
// Get the previous and current point
var previousPoint : CGPoint = ...
var currentPoint : CGPoint = ...
// Add new line (from previous to current point) to the existing path
CGPathMoveToPoint(linePath, nil, previousPoint.x, previousPoint.y)
CGPathAddLineToPoint(linePath, nil, currentPoint.x, currentPoint.y)
// Redraw line
line.removeFromParent()
line.path = linePath // Update path
self.addChild(line)
}
This works perfectly. However... After about 10 seconds the FPS goes rapidly from 60 FPS to 9 FPS. I also noticed that the memory usage is about 100 MB and more. This is not normal for a simple game that draws a moving circle and a path. Is this the correct way to do it?