问题
My SKSpriteNode follows this path in a counterclockwise direction, how do i make it so it follows the path in a clockwise direction?
Thanks in advance!
CGPathRef circle = CGPathCreateWithEllipseInRect(CGRectMake(0,0,50,50), NULL);
SKAction *followTrack = [SKAction followPath:circle asOffset:YES orientToPath:YES duration:5.0];
SKAction *forever = [SKAction repeatActionForever:followTrack];
[player2 runAction:forever];
回答1:
Instead of CGPathCreateWithEllipseInRect()
, use CGPathCreateMutable()
and CGPathAddArc()
to create the circle path and use the clockwise
parameter to control
the direction.
Untested code:
CGMutablePathRef circle = CGPathCreateMutable();
CGPathAddArc(circle, NULL, 25, 25, 25, 0, 2*M_PI, true);
CGPathCloseSubpath(circle);
回答2:
From Martin's answer a few changes cause the object to start and end at the same place:
In Objective C
CGMutablePathRef circle = CGPathCreateMutable();
CGPathAddArc(circle, NULL, -25, 0, 25, 0, 2*M_PI, true);
CGPathCloseSubpath(circle);
In swift
let path = CGPathCreateMutable()
CGPathAddArc(path, nil, -25, 0, 25, 0, CGFloat(2.0 * M_PI), true)
CGPathCloseSubpath(path)
来源:https://stackoverflow.com/questions/22746843/skaction-to-follow-circle-cgpathref-in-clockwise-direction