ios - 如何使用 CGPathRef 绘制对象弧线

标签 ios core-graphics sprite-kit

在我的 iOS 游戏中,我尝试沿路径移动对象(见下文):

enter image description here

我想将上面的三角形移动到框的底部。

但是我不知道如何很好地使用CGPathRefs。这是我正在尝试的:

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, 20, 0, 20, 0, M_PI/2, NO);
SKAction *moveTriangle = [SKAction followPath:path asOffset:YES orientToPath:YES duration:1.0];
[self.triangle runAction:moveTriangle];

而且我不断得到奇怪的结果。有人可以帮我调整我的路径以匹配上面的图片吗?谢谢!

最佳答案

使用原型(prototype)的想法

     // will arc around this sprite for demo
    SKSpriteNode *boxOrange = [SKSpriteNode spriteNodeWithColor:[UIColor orangeColor] size:CGSizeMake(30, 30)];
    boxOrange.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    [self addChild:boxOrange];

    SKSpriteNode *heroSprite = [SKSpriteNode spriteNodeWithColor:[UIColor blueColor] size:CGSizeMake(70, 70)];
    CGFloat offeset = 150; // change as required, ie bring hero closer to rotn point
    heroSprite.position = CGPointMake(-offeset, heroSprite.position.y);
    SKSpriteNode *guideContainer = [SKSpriteNode spriteNodeWithColor:[SKColor purpleColor] size:CGSizeMake(3, 3)];
    // for full effect - change guide container to clearColor
    // otherwise good for seeing where rotation point will occur
    [guideContainer addChild:heroSprite];

    [self addChild:guideContainer];
    guideContainer.position = boxOrange.position;

    [guideContainer runAction:[SKAction rotateToAngle:1.57 duration:3.0 shortestUnitArc:YES]];
    // just found shortestUnitArc action .. this will be handy for at times

关于ios - 如何使用 CGPathRef 绘制对象弧线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19552717/

相关文章:

ios - 我的游戏中应该有多少个 View Controller ?

ios - 快速检测 Sprite 节点是否存在

iOS 通过 XCode 将应用程序提交到 App Store 到国外 iTunes Connect 帐户

ios - 如何更改 UIBarButtonItem 的上边距

ios - 更新 UIImageView 占用太多内存

iphone - 如何通过另一个 CGMutalbePathRef 剪辑或减去 CGMutablePathRf?

ios - 为什么我的 "if"和 "else"语句都没有被执行?

ios - React-Native:异常 'Your app is missing support for the following URL schemes[#id.apps.googleusercontent.com]'

ios - 为导航栏设置与标签栏相同的视觉效果

iphone - 更改分组表边框半径