大佬教程收集整理的这篇文章主要介绍了使用Swift在向下循环中移动SKSpriteNode,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Thanx提前,
马库斯
r = a + bθ
螺旋基本上是一个美化圆(IMO),因此要以螺旋方式移动节点,您需要能够使用角度,半径和中心点计算圆上的点:
func pointOnCircle(#angle: CGFloat,#radius: CGFloat,#center: CGPoint) -> CGPoint { return CGPoint(x: center.x + radius * cos(anglE),y: center.y + radius * sin(anglE)) }
接下来,扩展SKAction,以便您可以轻松创建螺旋动作:
extension SKAction { static func spiral(#starTradius: CGFloat,endRadius: CGFloat,angle @R_976_10586@lAngle: CGFloat,centerPoint: CGPoint,duration: NSTimeInterval) -> SKAction { // The distance the node will travel away from/toWARDs the // center point,per revolution. let radiusPerRevolution = (endRadius - starTradius) / @R_976_10586@lAngle let action = SKAction.customActionWithDuration(duration) { node,time in // The current angle the node is at. let θ = @R_976_10586@lAngle * time / CGFloat(duration) // The equation,r = a + bθ let radius = starTradius + radiusPerRevolution * θ node.position = pointOnCircle(angle: θ,radius: radius,center: centerPoint) } return action } }
最后,一个使用的例子.在didMoveToView中:
let node = SKSpriteNode(color: UIColor.redColor(),size: CGSize(width: 10,height: 10)) node.position = CGPoint(x: size.width / 2,y: size.height / 2) addChild(nodE) let spiral = SKAction.spiral(starTradius: size.width / 2,endRadius: 0,angle: CGFloat(M_PI) * 2,centerPoint: node.position,duration: 5.0) node.runAction(spiral)
以上是大佬教程为你收集整理的使用Swift在向下循环中移动SKSpriteNode全部内容,希望文章能够帮你解决使用Swift在向下循环中移动SKSpriteNode所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。