Xcode 在不更改方向的情况下更改SpriteKit中UIBezierPath的旋转
我在做游戏。我想要两条单独的线顺时针旋转,当播放器触摸屏幕时,旋转应改为逆时针。现在,当它变为逆时针时,Xcode 在不更改方向的情况下更改SpriteKit中UIBezierPath的旋转,xcode,swift,sprite-kit,Xcode,Swift,Sprite Kit,我在做游戏。我想要两条单独的线顺时针旋转,当播放器触摸屏幕时,旋转应改为逆时针。现在,当它变为逆时针时,UIBezierPath会翻转节点。我不想翻转节点,只需以另一种方式旋转即可 func clockwise() { let dx = leftside.position.x - self.frame.width / 2 let dy = leftside.position.y - self.frame.height / 2 let rad = atan2(dy, dx
UIBezierPath
会翻转节点。我不想翻转节点,只需以另一种方式旋转即可
func clockwise() {
let dx = leftside.position.x - self.frame.width / 2
let dy = leftside.position.y - self.frame.height / 2
let rad = atan2(dy, dx)
let path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, speed: 250)
leftside.runAction(SKAction.repeatActionForever(follow).reversedAction())
let dx1 = rightside.position.x - self.frame.width / 2
let dy1 = rightside.position.y - self.frame.height / 2
let rad1 = atan2(dy1, dx1)
let path1 = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad1, endAngle: rad1 + CGFloat(M_PI * 4), clockwise: true)
let follow1 = SKAction.followPath(path1.CGPath, asOffset: false, orientToPath: true, speed: 250)
rightside.runAction(SKAction.repeatActionForever(follow1).reversedAction())
}
func counterclockwise() {
let dx = leftside.position.x - self.frame.width / 2
let dy = leftside.position.y - self.frame.height / 2
let rad = atan2(dy, dx)
let path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, speed: 250)
leftside.runAction(SKAction.repeatActionForever(follow))
let dx1 = rightside.position.x - self.frame.width / 2
let dy1 = rightside.position.y - self.frame.height / 2
let rad1 = atan2(dy1, dx1)
let path1 = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 85, startAngle: rad1, endAngle: rad1 + CGFloat(M_PI * 4), clockwise: true)
let follow1 = SKAction.followPath(path1.CGPath, asOffset: false, orientToPath: true, speed: 250)
rightside.runAction(SKAction.repeatActionForever(follow1))
}
在创建
UIBezierPath
时,不要在最后调用reversedAction()
,而是将顺时针方向设置为false
?我尝试过,当我将顺时针方向设置为false时,旋转不会发生。不在任何方向旋转