我需要不断地创建一个cgpath对象。目前我是这样做的:
但问题是,随着时间的推移,帧速率逐渐降低。我需要做出哪些改变才能使帧速率不再下降?
我的目标是创建一个无限随机路径。
func createLine(){
var rand = randomBetweenNumbers(1, 2)
currentY--
if rand < 1.5{
currentX--
CGPathAddLineToPoint(leftPath, nil, currentX, currentY)
}else{
currentX++
CGPathAddLineToPoint(leftPath, nil, currentX, currentY)
}
CGPathAddLineToPoint(rightPath, nil, currentX+tileSize, currentY)
lineNode.path = leftPath
rightNode.path = rightPath
}
然后像这样调用它:
NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: Selector("startTile"), userInfo: nil, repeats: true)
但问题是,随着时间的推移,帧速率逐渐降低。我需要做出哪些改变才能使帧速率不再下降?
我的目标是创建一个无限随机路径。
CADisplayLink
而不是NSTimer
,因为它与显示刷新同步触发。 - Matteo Piombo