【发布时间】: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