ios - 停止和继续 SKAction

标签 ios sprite-kit textures skaction

我们如何停止对特定帧(纹理)的操作?我想制作一个在触摸结束后停止的动画。我搜索了文档,但没有运气。我发现的唯一一件事是方法 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/

相关文章:

ios - 在 UIViewControllerAnimatedTransitioning 中隐藏状态栏

ios - 初始 View 控件中的 PrepareforSegue

ios - 如何在 SpriteKit 场景中控制 UITableView 的 Z-Order?

xcode - 如何记录 CGVector?

ios - Sprite Kit 中的单个粒子和物理

unity3d - (Unity3d)为什么四边形的视频纹理质量低于原始视频?

android - 纹理仅显示为黑色

c++ - 用于纹理上传的OpenGL PBO,无法理解一件事

javascript - React Native touchableopacity onpress 不起作用

ios - 使用自定义 UITableViewCells 子类 UITableView