在更新动画时运行遵循路径的SKAction

时间:2015-10-28 23:31:13

标签: sprite-kit skaction

我正在使用精灵套件。我需要我的角色在更新动画时沿着路径移动。例如,当我的skspritenode开始向左移动时,我想将运行动画更改为向左运行动画。

我尝试了许多序列组合,运行块等,但没有任何工作。有什么建议。下面的伪代码:

//run initial run animation
//get array of points to move to
//load skactions into an array 
   //upon completion of an skaction re-evaluate which animation to use.
//repeat

//run sequence of SKActions

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

好的,我想出了什么。为了澄清我想要的东西,我想在一个数组中取一系列点并通过一个函数运行它们,这个函数将移动我的skspritenode并在其上运行与我的角色运行所需的方向相对应的动画。这就是我的所作所为:

//我和j在这里是int类变量,不要问为什么我有两个,但它起作用所以我没有改变它。

    for (;i<len;i++) {
        [actions_array addObject:[SKAction moveTo:CGPointMake(apath[i].x, apath[i].y) duration:1.0]];
        [actions_array addObject:[SKAction runBlock:^(void){
            j++;
//remove the previous action just in case
                [self removeActionForKey:[NSString stringWithFormat:@"%d",j-1]];
                NSArray* frames = [self returnAnimForMoveToPt:CGPointMake(path_to_goal[j+1].x, path_to_goal[j+1].y)];
                [self runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:frames timePerFrame:1.0/30.0]] withKey:[NSString stringWithFormat:@"%d",j]];
            }]];
            }

    [self run

Action:[SKAction sequence:actions_array] completion:^(void){
                //******movement complete, at location*******!!!!!!!!
                [self goIdle];
//other completion handl
            }];

基本上我只是运行移动指令,然后重复运行带有动画的runBlocks。希望这会有所帮助。

相关问题