【发布时间】:2014-11-20 00:06:49
【问题描述】:
更新
更多信息在这里:Poor performance with SKShapeNode in Sprite Kit
我正在学习新的 Swift 语言。为了挑战自己,我尝试在 iOS 8 上使用 SpriteKit 构建 Curve Fever 克隆。我正在使用 CGPath 在玩家身后绘制一条路径(一个圆圈)。
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)
}
这非常有效。然而...... 大约 10 秒后,FPS 从 60 FPS 快速变为 9 FPS。我还注意到内存使用量约为 100 MB 甚至更多。这对于绘制移动圆圈和路径的简单游戏来说是不正常的。这是正确的做法吗?
【问题讨论】:
标签: ios swift ios8 sprite-kit