遵循SKAction无法正常工作的路径

时间:2013-12-12 14:13:00

标签: ios path sprite-kit skaction

我有一个CGMuatbleCGPathRef,我正在尝试创建一个路径引用移动我的外星人。我现在保持简单,但后来会很复杂。

我有下面的代码将SpriteNode移动到一个点,但他从不移动。谁能指出我做错了什么?我有一个动画动作在他身上运行,也有重复动作。

首先调用方法启动动画纹理帧(作品)

-(void)walkingBear
{
//This is our general runAction method to make our bear walk.
[spaceMosquito runAction:[SKAction repeatActionForever:
                  [SKAction animateWithTextures:moqFrames
                                   timePerFrame:0.4f
                                         resize:NO
                                        restore:YES]] withKey:@"walkingInPlaceBear"];
return;
}

移动外星人的行动

-(void) normalStance {
CGMutablePathRef cgpath = CGPathCreateMutable();
CGPoint endPos = CGPointMake(300, 600);
CGPoint startPos = CGPointMake(700, 900);

CGPathMoveToPoint(cgpath, nil, startPos.x, startPos.y);
CGPathMoveToPoint(cgpath, nil, endPos.x, endPos.y);

[spaceMosquito runAction:[SKAction followPath:cgpath duration:5.0f ] withKey:@"moveme"];
CGPathRelease(cgpath);

}

1 个答案:

答案 0 :(得分:2)

您没有在代码中创建路径!您只是将路径的起点从起点移动到终点,但没有创建路径。

用CGPathAddLineToPoint替换CGPathMoveToPoint的第二次调用 这将创建一个精灵可以遵循的线路。

相关问题