문제

I have a CGMuatbleCGPathRef and I am trying to create a path ref to move my alien. I'm keeping it simple right now, but these will be complex later on.

I have the code below to move the SpriteNode to one point, but he never moves. Can someone point out what i'm doing wrong? I have an animation action running on him with repeat action also.

Method called first to start the animation texture frames ( works )

-(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;
}

The Action to move the alien

-(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);

}

도움이 되었습니까?

해결책

You are not creating a path in your code! You are just moving the start of the path from start point to end point but no path is created.

Replace the second call of CGPathMoveToPoint by CGPathAddLineToPoint The will create a line path your sprite could follow.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top