我正在尝试为要遵循的节点创建 CGPath,但是当我尝试使用 SKShapeNode 中定义的动作和常量从 608_hd_best_practices_for_building_spritekit_games 滑动时,我得到错误Extra argument 'count' in call。有什么想法吗?
import SpriteKit
class GameScene: SKScene {
var groundNode: SKSpriteNode? = SKSpriteNode()
var path = [CGPoint]()
override func didMoveToView(view: SKView) {
groundNode = childNodeWithName("ground") as? SKSpriteNode
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
path = [CGPoint]()
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
var newPoint = touches.anyObject()?.locationInNode(groundNode)
path.append(newPoint!)
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.25
sprite.yScale = 0.25
sprite.position = path.first!
groundNode?.addChild(sprite)
// TODO: this currently isnt working
let count = path.count
// CGPathRef p = [SKShapeNode shapeWithSplinePoints:points]
let p: CGPathRef = SKShapeNode(splinePoints: path, count: count)
let speed:CGFloat = 1.0
let action = SKAction.followPath(p, speed: speed)
sprite.runAction(action)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}