내가 따라야 할 노드에 대한 CGPath를 작성하려하지만 행동에 정의 된 상수 608_hd_best_practices_for_building_spritekit_games에서 슬라이드로 SKShapeNode를 사용하여 시도 때 내가 전화에 오류 추가 인수 '수'를 얻을. 이견있는 사람?스위프트 SKShapeNode의 shapeWithSplinePoints
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 */
}
}
경로 * 동등한 CGPoint 아닌 다음과 같이 변경합니다 오히려 CGPoint이 NSValue 인스턴스에 싸여되어있는 NSArray, 그래서 유형 함수 정의와 일치하지 않는 경우 https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKShapeNode_Ref/index.html#//apple_ref/occ/clm/SKShapeNode/shapeNodeWithPoints:count를 참조하십시오. : – LearnCocos2D