Stroke a CGPathRef in Objective C

149 views Asked by At

I've looked at similar questions here but I can't make the examples work for me. Since the way I'm creating this path is a bit different than previous examples, I'll state my problem:

I'm trying to visualize a path that sprites are made to follow in a SpriteKit game.

I call this in another method, where I add the shipPath to a SKAction

CGPathRef shipPath = [self buildEnemyShipMovementPath:enemy];

SKAction *followPath = [SKAction followPath:shipPath
                                 asOffset:YES
                             orientToPath:YES
                                 duration:7];

The path creation method:

- (CGPathRef)buildEnemyShipMovementPath:(SKSpriteNode*)enemy
{
   UIBezierPath* bezierPath = [UIBezierPath bezierPath];

   // ... path creation code ... //

   return bezierPath.CGPath;
}

Given this, what should I do to "see" the path on screen, potentially I'd like to toggle it on and off, for debugging purposes.

1

There are 1 answers

0
Andrey Gordeev On
SKShapeNode *pathNode = [[SKShapeNode alloc] init];
pathNode.path = [self buildEnemyShipMovementPath:enemy];
pathNode.strokeColor = [SKColor redColor];
pathNode.lineWidth = 0.5f;
pathNode.alpha = 0.4;
pathNode.glowWidth = 5.f;
[self addChild:pathNode]