【发布时间】:2015-08-11 10:36:48
【问题描述】:
我需要不断地创建一个 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)
但问题是,随着时间的推移,帧数会越来越低。有什么我必须改变的,以使帧率不再下降吗?
我的目标是创建一条随机的无限路径。
【问题讨论】:
-
我猜您需要转储路径的旧部分。否则,您最终会拥有越来越多的路径段。或者,为什么不在每次到达当前路径的末端时创建一个新路径?
-
我无法真正创建新路径,因为我需要它是无止境的,或者至少新路径对玩家不可见。
-
这应该有助于line caching
-
你能不能把你的路径点放在一个数组中,然后画出应该在屏幕上实际可见的东西?顺便说一句,尽管有
NSTimer,您可能更喜欢使用CADisplayLink,因为它会与显示刷新同步触发。
标签: swift sprite-kit infinite frame-rate cgpath