SKAction go to and stop at a specific frame

戏子无情 提交于 2020-01-05 08:50:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!