Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top