我正在尝试为节点创建一个要遵循的CGPath,但是当我尝试使用CGPath中的操作和常量幻灯片中定义的SKShapeNode时,就会在call中得到错误额外的参数'count‘。有什么想法吗?
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 */
}
}发布于 2014-12-26 19:20:04
init(splinePoints:count:)以一个UnsafeMutablePointer<CGPoint> (即CGPoint的C数组)和一个无符号整数作为参数。它还返回一个SKShapeNode对象,而不是一个CGPathRef。试试下面的..。
let p = SKShapeNode(splinePoints: &path, count: UInt(count))编辑:还进行以下更改
let speed:CGFloat = 1.0
let action = SKAction.followPath(p.path, speed: speed)
sprite.runAction(action)https://stackoverflow.com/questions/27659656
复制相似问题