停止并继续SKAction

时间:2014-12-01 21:35:36

标签: ios sprite-kit textures skaction

我们如何停止对特定帧(纹理)的操作?我想制作一个在触摸结束后停止的动画。我通过文档搜索,但没有运气。我唯一发现的是方法removeAllActions和removeActionForKey:但我不想完全删除一个动作,我只是想在正确的纹理上停止它 - 动画信号停止时的当前纹理。

//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;
}

1 个答案:

答案 0 :(得分:2)

您可以使用speed属性暂停/恢复操作:

SKAction *action = [_hero actionWithKey:@"move"];

action.speed = 0;    // to pause

action.speed = 1;    // to resume