作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为要遵循的节点创建 CGPath,但是当我尝试使用 608_hd_best_practices_for_building_spritekit_games 中的操作和常量幻灯片中定义的 SKShapeNode 时,我收到错误调用中的额外参数“计数”。有什么想法吗?
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 */
}
}
最佳答案
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)
关于Swift SKShapeNode shapeWithSplinePoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37086510/
我正在尝试为要遵循的节点创建 CGPath,但是当我尝试使用 608_hd_best_practices_for_building_spritekit_games 中的操作和常量幻灯片中定义的 SKS
我是一名优秀的程序员,十分优秀!