我们如何停止对特定帧(纹理)的操作?我想制作一个在触摸结束后停止的动画。我搜索了文档,但没有运气。我发现的唯一一件事是方法 removeAllActions 和 removeActionForKey: 但我不想完全删除一个 Action ,我只想将它停止在正确的纹理 - 动画信号停止时的当前纹理。
//This is from the scene init method
NSMutableArray *frames = [NSMutableArray array];
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"hero-movement"];
int numImages = atlas.textureNames.count;
for (int i=1; i <= numImages; i++) {
NSString *texture = [NSString stringWithFormat:@"animation_00%d", i];
SKTexture *t = [atlas textureNamed:texture];
[frames addObject:t];
}
self.animation = frames;
这是我在 touchesBegan 中用来启动动画的方法:
-(void)move :(float)delay
{
//This is our general runAction method to make our bear walk.
//By using a withKey if this gets called while already running it will remove the first action before
//starting this again.
[self.hero runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:self.animation
timePerFrame:delay
resize:NO
restore:YES]] withKey:@"move"];
return;
}
最佳答案
您可以使用 speed
属性来暂停/恢复操作:
SKAction *action = [_hero actionWithKey:@"move"];
action.speed = 0; // to pause
或
action.speed = 1; // to resume
关于ios - 停止和继续 SKAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27237773/