SKAction to follow Circle CGPathRef in clockwise direction

女生的网名这么多〃 提交于 2019-12-08 09:03:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!