2

I've used CGPath to create a race track by stroking the path and offsets of it to draw the road and lines. My hope was that I could use this CGPath in SpriteKit so that I could make a car sprite follow the track. I can get a sprite to follow the entire path from start to finish using SKAction.followPath (screenshot added at bottom of post.)

However, my issue is I sometimes want a car sprite to move from the start to the half-way point (or 25% or some fraction of the path.)

I don't see a way of doing with with an SKAction so I was looking into a way of taking a CGPath and splitting it to whatever fraction of the path I needed but I've yet to find anything that seems to do that. I'm reasonably hopeful it can be done since in a CAShapeLayer you can set strokeStart and strokeEnd to specify where you want the path stroked from percent start to percent end so it looks like something like this has already been implemented.

Is there any way of either getting SpriteKit to set the start and end point of followPath or modifying a CGPath so that it returns a subpath?

car race screenshot

abaroody
  • 31
  • 1
  • The only way I can think of, to control a car that is moving along the path, in this case when it comes to SKActions is to affect on action speed or its paused property(eg to pause the action at specific moment). Probably not a solution though, but good things to keep in mind. – Whirlwind Jan 13 '17 at 19:02
  • 1
    @abaroody You should re-create the new CGPath, starting from the "moveTo" point you wish. If you have some problem to handle these paths , take a look to [this](http://stackoverflow.com/a/36374209/1894067) answer. – Alessandro Ornano Jan 13 '17 at 19:16
  • @abaroody Of course I was commenting the way without re-creating the path. If you are fine to re-create it, then you could go with what Alessandro pointed. – Whirlwind Jan 13 '17 at 19:49

0 Answers0