gpt4 book ai didi

ios - 如何使用 CGPathRef 弧形对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:07 25 4
gpt4 key购买 nike

在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com