【发布时间】:2017-07-10 11:32:00
【问题描述】:
这是一个由四个单独的精灵组成的轮子。我的目标是将它们作为轮子旋转。我已经尝试过'UIBezier' arccenter 类,但最终结果是单个精灵沿着中心移动但也旋转了它的形状,导致了不想要的结果。这是相关的代码。 'orientToPath' 当设置为 true 时,会旋转精灵本身。
//path rotation
let dx = whlPurple.position.x - self.size.width/2
let dy = whlPurple.position.y - (whlRed.size.height/2 + (whlPurple.position.y - whlRed.size.height))
let rad = atan2(dy, dx)
let radius = sqrt((dx*dx) + (dy*dy))
let path = UIBezierPath(arcCenter: CGPoint(x: self.size.width/2, y: (whlRed.size.height/2 + (whlPurple.position.y - whlRed.size.height))), radius: radius, startAngle: rad, endAngle: rad + CGFloat(M_PI * 6), clockwise: true)
let follow = SKAction.follow(path.cgPath, asOffset: false, orientToPath: true, speed: 200)
whlPurple.run(SKAction.repeatForever(follow))
【问题讨论】:
标签: swift sprite-kit