【发布时间】:2016-05-17 16:02:29
【问题描述】:
在我的应用程序中,我有一个 Sprite 围绕另一个 sprite 盘旋。我希望这个精灵在屏幕被按住时加速。我已经实现了加速功能,但我似乎无法弄清楚为什么当屏幕被点击和放开后精灵会重置回某个位置。我有一种感觉,我知道为什么,但我已经尝试修复它,但我似乎无法更接近解决方案。代码如下。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let dx = Slider.accessibilityActivationPoint.x
let dy = Slider.accessibilityActivationPoint.y
let rad = atan2(dx, dy)
let Path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 90, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 400)
//let rotate = SKAction.rotateByAngle(75, duration: 100)
Slider.runAction(SKAction.repeatActionForever(follow).reversedAction())
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
let dx = Slider.accessibilityActivationPoint.x
let dy = Slider.accessibilityActivationPoint.y
let rad = atan2(dy, dx)
let Path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 90, startAngle: 9, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 150)
Slider.runAction(SKAction.repeatActionForever(follow).reversedAction())
}
func moveClockWise(){
let dx = Slider.position.x / 2
let dy = Slider.position.y / 2
let rad = atan2(dy, dx)
let Path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 90, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 150)
//let rotate = SKAction.rotateByAngle(75, duration: 100)
Slider.runAction(SKAction.repeatActionForever(follow).reversedAction())
//Slider.runAction(SKAction.repeatActionForever(rotate).reversedAction())
}
【问题讨论】:
标签: swift sprite-kit uibezierpath