问题
I've a Sprite that animates via texture array, with spinLeft
being increasing the array index, and spinRight
decreasing the index, as shown in the answer to my other question here:
https://stackoverflow.com/a/44792902/6593818
The animation is working fine, but now I am trying to control the animation via a gesture recognizer or some other form of input.
In the referenced question, the spin function has an input for speed (the TimeInterval), so I just need an output from a gesture recognizer:
I want to figure out what to do in terms of getting the object to react to my finger in the same way as shown in this video: https://youtu.be/qjzeewpVN9o
The video is beyond just a basic UIPanGesture
reading velocity, I think. At least, I'm not sure how to implement it.
This project is to showcase a friend's sculptures via photography.
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)
}
来源:https://stackoverflow.com/questions/44814650/how-to-properly-get-a-gesture-recognizer-to-fluidly-spin-a-sprite-according-to-v