Animation 如何通过反复触摸使动画不中断地完成?(雪碧套装图集)

Animation 如何通过反复触摸使动画不中断地完成?(雪碧套装图集),animation,xcode5,sprite-kit,Animation,Xcode5,Sprite Kit,我正在使用IOS sprite工具包创建一个由触摸驱动的动画(在.atlas文件中)。如何通过反复触摸使动画不中断地完成? 我知道我忽略了一些非常简单的事情 -(void) setUpActions { SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"Wheel"]; SKTexture *Wheel1 = [atlas textureNamed:@"Wheel1.png"]; SKTexture *Wheel2 = [atlas t

我正在使用IOS sprite工具包创建一个由触摸驱动的动画(在.atlas文件中)。如何通过反复触摸使动画不中断地完成? 我知道我忽略了一些非常简单的事情

-(void) setUpActions {

SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"Wheel"];

SKTexture *Wheel1 = [atlas textureNamed:@"Wheel1.png"];
SKTexture *Wheel2 = [atlas textureNamed:@"Wheel2.png"];
SKTexture *Wheel3 = [atlas textureNamed:@"Wheel3.png"];
SKTexture *Wheel4 = [atlas textureNamed:@"Wheel4.png"];
SKTexture *Wheel5 = [atlas textureNamed:@"Wheel5.png"];
SKTexture *Wheel6 = [atlas textureNamed:@"Wheel6.png"];
SKTexture *Wheel7 = [atlas textureNamed:@"Wheel7.png"];
SKTexture *Wheel8 = [atlas textureNamed:@"Wheel8.png"];
SKTexture *Wheel9 = [atlas textureNamed:@"Wheel9.png"];

NSArray *atlasTexture = @[Wheel1, Wheel2, Wheel3, Wheel4, Wheel5, Wheel6, Wheel7, Wheel8, Wheel9];

SKAction* atlasAnimation = [SKAction animateWithTextures:atlasTexture timePerFrame:0.1];

   SKAction *resetTexture = [SKAction setTexture:[SKTexture textureWithImageNamed:@"Wheel1.png"] ];

runAnimation = [SKAction sequence:@[atlasAnimation,resetTexture]];

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    SKSpriteNode* Wheel = (SKSpriteNode*)[self childNodeWithName:@"Wheel"];
    [Wheel runAction:runAnimation];

   if (_tapCount < 1) {

      //How do I cancel the touches until the animation is complete?
       NSLog(@"STOP touches???");
   }
}
-(无效)设置操作{
SKTextureAtlas*atlas=[SKTextureAtlas atlasNamed:@“Wheel”];
SKTexture*Wheel1=[atlas TextureName:@“Wheel1.png”];
SKTexture*Wheel2=[atlas TextureName:@“Wheel2.png”];
SKTexture*Wheel3=[atlas TextureName:@“Wheel3.png”];
SKTexture*Wheel4=[atlas TextureName:@“Wheel4.png”];
SKTexture*Wheel5=[atlas TextureName:@“Wheel5.png”];
SKTexture*Wheel6=[atlas TextureName:@“Wheel6.png”];
SKTexture*Wheel7=[atlas TextureName:@“Wheel7.png”];
SKTexture*Wheel8=[atlas TextureName:@“Wheel8.png”];
SKTexture*Wheel9=[atlas TextureName:@“Wheel9.png”];
NSArray*atlasTexture=@[Wheel1、Wheel2、Wheel3、Wheel4、Wheel5、Wheel6、Wheel7、Wheel8、Wheel9];
SKAction*atlasAnimation=[SKAction animateWithTextures:AtlastTexture timePerFrame:0.1];
SKAction*resetTexture=[SKAction setTexture:[SKTexture TextureWithimageName:@“Wheel1.png”];
runAnimation=[SKAction sequence:@[atlasAnimation,resetTexture]];
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
SKSpriteNode*车轮=(SKSpriteNode*)[自生子女节点名称:@“车轮];
[轮子运行动作:运行动画];
如果(_tapCount<1){
//如何取消触摸直到动画完成?
NSLog(@“停止接触?”);
}
}

首先,有一种更简单的方法可以添加纹理:

    NSMutableArray *animations = [[NSMutableArray alloc] init];

    for (int i = 0; i < [atlas.textureNames count]; i++) {
    NSString *temp = [NSString stringWithFormat:@"Wheel%d.png", i + 1]; // name your animations from zero to avoid adding 1 here
    SKTexture *texture = [atlas textureNamed:temp];
    [animations addObject:texture];
}
您可能应该从其他方法调用animation start。然后在联系方式下你可以检查

 if ([Wheel actionForKey:@"wheelAnimation"]) {
    return;
    }
这将从touchs方法中退出,而不在return语句后执行代码

或者在您的代码中:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

     SKSpriteNode* Wheel = (SKSpriteNode*)[self childNodeWithName:@"Wheel"];

    if (![Wheel actionForKey:@"wheelAnimation"]) { // everything in this block will not trigger if it finds animation
        [Wheel runAction:runAnimation];

       if (_tapCount < 1) {

          //How do I cancel the touches until the animation is complete?
           NSLog(@"STOP touches???");
       }
     }
   }
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
SKSpriteNode*车轮=(SKSpriteNode*)[自生子女节点名称:@“车轮];
如果(![Wheel actionForKey:@“wheelAnimation”]){//如果找到动画,则不会触发此块中的所有内容
[轮子运行动作:运行动画];
如果(_tapCount<1){
//如何取消触摸直到动画完成?
NSLog(@“停止接触?”);
}
}
}

还要注意的是,触摸实际上是在touchesBegin方法中开始的,因此最好将代码放在其中。

首先,有一种更简单的方法可以添加纹理:

    NSMutableArray *animations = [[NSMutableArray alloc] init];

    for (int i = 0; i < [atlas.textureNames count]; i++) {
    NSString *temp = [NSString stringWithFormat:@"Wheel%d.png", i + 1]; // name your animations from zero to avoid adding 1 here
    SKTexture *texture = [atlas textureNamed:temp];
    [animations addObject:texture];
}
您可能应该从其他方法调用animation start。然后在联系方式下你可以检查

 if ([Wheel actionForKey:@"wheelAnimation"]) {
    return;
    }
这将从touchs方法中退出,而不在return语句后执行代码

或者在您的代码中:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

     SKSpriteNode* Wheel = (SKSpriteNode*)[self childNodeWithName:@"Wheel"];

    if (![Wheel actionForKey:@"wheelAnimation"]) { // everything in this block will not trigger if it finds animation
        [Wheel runAction:runAnimation];

       if (_tapCount < 1) {

          //How do I cancel the touches until the animation is complete?
           NSLog(@"STOP touches???");
       }
     }
   }
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
SKSpriteNode*车轮=(SKSpriteNode*)[自生子女节点名称:@“车轮];
如果(![Wheel actionForKey:@“wheelAnimation”]){//如果找到动画,则不会触发此块中的所有内容
[轮子运行动作:运行动画];
如果(_tapCount<1){
//如何取消触摸直到动画完成?
NSLog(@“停止接触?”);
}
}
}

还要注意的是,触摸实际上是在touchesBegin方法中开始的,因此最好将代码放在其中。

您可以通过向序列中添加两个操作来完成此操作:

-(void) setUpActions {

    SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"Wheel"];

    // build atlasTexture array dynamically

    NSMutableArray *atlasTexture = [NSMutableArray array];

    int totalWheelImages = atlas.textureNames.count;

    for (int i=1; i <=totalWheelImages; i++) {
        NSString *textureName = [NSString stringWithFormat:@"Wheel%d", i];

        SKTexture *temp = [atlas textureNamed:textureName];

        [atlasTexture addObject:temp];

    }

    // SKAction to stop user interaction

    SKAction *start = [SKAction runBlock:^{

        [self setUserInteractionEnabled:FALSE];

        }];

    SKAction* atlasAnimation = [SKAction animateWithTextures:atlasTexture timePerFrame:0.1];

    SKAction *resetTexture = [SKAction setTexture:[SKTexture textureWithImageNamed:@"Wheel1.png"] ];

    // SKAction to restart user interaction

    SKAction *end = [SKAction runBlock:^{

        [self setUserInteractionEnabled:TRUE];

        }];

    runAnimation = [SKAction sequence:@[start, atlasAnimation, resetTexture, end]];

}
-(无效)设置操作{
SKTextureAtlas*atlas=[SKTextureAtlas atlasNamed:@“Wheel”];
//动态构建AtlastTexture阵列
NSMutableArray*AtlastTexture=[NSMutableArray];
int totalWheelImages=atlas.textureNames.count;

对于(int i=1;i,您可以通过向序列中添加两个操作来完成此操作:

-(void) setUpActions {

    SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"Wheel"];

    // build atlasTexture array dynamically

    NSMutableArray *atlasTexture = [NSMutableArray array];

    int totalWheelImages = atlas.textureNames.count;

    for (int i=1; i <=totalWheelImages; i++) {
        NSString *textureName = [NSString stringWithFormat:@"Wheel%d", i];

        SKTexture *temp = [atlas textureNamed:textureName];

        [atlasTexture addObject:temp];

    }

    // SKAction to stop user interaction

    SKAction *start = [SKAction runBlock:^{

        [self setUserInteractionEnabled:FALSE];

        }];

    SKAction* atlasAnimation = [SKAction animateWithTextures:atlasTexture timePerFrame:0.1];

    SKAction *resetTexture = [SKAction setTexture:[SKTexture textureWithImageNamed:@"Wheel1.png"] ];

    // SKAction to restart user interaction

    SKAction *end = [SKAction runBlock:^{

        [self setUserInteractionEnabled:TRUE];

        }];

    runAnimation = [SKAction sequence:@[start, atlasAnimation, resetTexture, end]];

}
-(无效)设置操作{
SKTextureAtlas*atlas=[SKTextureAtlas atlasNamed:@“Wheel”];
//动态构建AtlastTexture阵列
NSMutableArray*AtlastTexture=[NSMutableArray];
int totalWheelImages=atlas.textureNames.count;

对于(int i=1;我很好,谢谢!当我的手指在屏幕上时,我可以让动画运行,但一旦我松开,动画就会停止。它在停止之前仍然没有完成。我会尝试从另一个方法运行动画,只要我有更多的时间来处理它。再次感谢!哦,是的,我执行了重置操作。我在另一个问题上看到了n他们设置了一个空白的场景图像来阻止触摸。这听起来也是一个很酷的主意。好的,谢谢!我可以在手指在屏幕上的时候让动画运行,但是一旦我放了动画,动画就停止了。在停止之前它仍然没有完成。我会尝试用另一种方法运行动画,只要我有多一点时间再次感谢!哦,是的,我采取了重置动作。我在另一个问题上看到他们设置了一个空白的场景图像来阻止触摸。这听起来也是个很酷的主意。