문제

I am using a simple A* Pathfinding algorithm to create a path between two points (the green and red circles below), each square is an SKSpriteNode (with a CGPoint [x,y] position). I want to animate another SKSpriteNode along a smooth path that passes through each point.

My thinking was that I could use the SKAction -followPath:duration: to do this but I am having trouble working out how to create/specify the CGPath. Any help would be much appreciated.

enter image description here

도움이 되었습니까?

해결책

You can create a simple CGPath like this

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL, 100, 0);
CGPathAddLineToPoint(path, NULL, 100, 100);

Depending on what you want to achieve you can add different elements to your path like arcs, curves, rects... You can find more about it here.

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