如何正确地得到一个手势识别器来根据速度stream畅地旋转一个精灵
我有一个Sprite通过纹理数组进行animation处理, spinLeft
增加了数组索引,而spinRight
减less了索引,如下面对我的其他问题的回答所示:
https://stackoverflow.com/a/44792902/6593818
animation工作正常,但现在我试图通过手势识别器或其他forms的input来控制animation 。
在引用的问题中,旋转函数有一个速度input(TimeInterval),所以我只需要一个手势识别器的输出:
我想弄清楚如何让对象对我的手指做出反应,就像本video所示: https : //youtu.be/qjzeewpVN9o
video不仅仅是一个基本的UIPanGesture
阅读速度,我想。 至less,我不知道如何实现它。
这个项目是通过摄影展示朋友的雕塑。
func spin(direction: Direction, timePerFrame: TimeInterval) { nextTextures = [] for _ in 0...6 { var index = initialTextures.index(of: sprite.texture!) // Left is ascending, right is descending: switch direction { case .left: if index == (initialTextures.count - 1) { index = 0 } else { index! += 1 } case .right: if index == 0 { index = (initialTextures.count - 1) } else { index! -= 1 } } let nextTexture = initialTextures[index!] nextTextures.append(nextTexture) sprite.texture = nextTexture } let action = SKAction.repeatForever(.animate(with: nextTextures, timePerFrame: timePerFrame)) sprite.run(action) }