【发布时间】:2015-10-23 01:19:23
【问题描述】:
我在 swift 2.0 中使用 SpriteKit 写了几行简单的代码来尝试使用 CGPathCreateMutable() 来绘制和创建如下所示的行:
var lineNode = SKShapeNode()
var pathToDraw = CGPathCreateMutable()
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
let location = touch.locationInNode(self)
CGPathMoveToPoint(pathToDraw, nil, location.x, location.y)
lineNode.path = pathToDraw
lineNode.strokeColor = SKColor.redColor()
self.addChild(lineNode)
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let positionInScene = touch.locationInNode(self)
CGPathAddLineToPoint(pathToDraw, nil, positionInScene.x, positionInScene.y)
lineNode.path = pathToDraw
//pathToDraw
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
lineNode.removeFromParent()
}
绘制了一条红色路径,然后在我抬起手指后将其移除。我能够删除 lineNode 精灵。但是我无法在绘制后删除路径?绘制第二条线时,我可以看到第一条路径的“残余”。如果我继续绘制应用程序将崩溃。我发现它曾经通过做删除它
CGPathRelease(pathToDraw) //in obj-C at least
但后来我发现我不再需要这样做,因为它是一个自主的过程?
如何删除它?谢谢!
【问题讨论】:
标签: sprite-kit cgpath