【问题标题】:stopping and continuing a SKAction停止和继续 SKAction
【发布时间】:2014-12-01 21:35:36
【问题描述】:

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

【问题讨论】:

  • 你有什么办法解决这个问题?您是否尝试过类似 touchesDidEnd:withEvent: 的操作?你有什么代码?
  • 这里是代码。我尝试在 touchesEnded 中使用 removeActionForKey: 但这会删除一个动作,并设置我不想要的纹理。
  • 你可以使用 for 循环,并循环遍历帧中的每个纹理,当用户放开屏幕时,你可以设置任何你想要结束的纹理,为那个特定的纹理(int i = 0; i
  • 我不太清楚你在说什么...我需要停在某个纹理上,但这需要是基于运动的纹理,不是我选择的...
  • 您可以删除该操作,您可以暂停一个节点,这也将暂停该节点的操作。这些是你可以做的事情。如果您需要跟踪动画帧以便从离开的位置继续播放动画,则必须使用 update: 或带有 wait 和 runBlock 操作的序列手动循环帧。

标签: ios sprite-kit textures skaction


【解决方案1】:

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

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

action.speed = 0;    // to pause

action.speed = 1;    // to resume

【讨论】:

  • 谢谢,我刚刚测试了你的建议,它确实有效。我已经使用结合 runBlock 和等待操作的序列解决了一个问题,但我也可以接受这作为一个可行的解决方案。
猜你喜欢
  • 1970-01-01
  • 2014-07-01
  • 2018-08-22
  • 1970-01-01
  • 2011-06-15
  • 2015-03-07
  • 2023-03-27
  • 2015-08-09
  • 1970-01-01
相关资源
最近更新 更多