问题
Flash has gotoAndPlay() and gotoAndStop() methods for movie clips to skip to any frame. I don't see any methods in SKAction class but is there a way or workaround to simulate this for SKAction instances?
EDIT: Additional info on gotoAndPlay and gotoAndStop: gotoAndPlay(n) brings the playhead to the nth frame. If the clip is 30 frames long and you call gotoAndPlay(15) you start playing from the 15th frame and stop at 30. gotoAndStop(n) takes the animation to the nth frame and stops there without playing.
回答1:
There is no action to play from frame x to y. But it's easy to replicate because the animate actions..
+ (SKAction *)animateWithTextures:(NSArray *)textures
timePerFrame:(NSTimeInterval)sec
.. take an array of textures as input. You either create the array just with the specific frame textures you want to play, or if you already have an array allFrames
with all textures you can get a new array with the desired frames like so if you wanted to play from frame 15 to end:
NSRange range = NSMakeRange(15, allFrames.count - 15);
NSArray* animFrames = [allFrames subarrayWithRange:range];
SKAction anim = [SKAction animateWithTextures:animFrames timePerFrame:0.1];
来源:https://stackoverflow.com/questions/24445987/skaction-go-to-and-stop-at-a-specific-frame