gpt4 book ai didi

ios - 向固定点旋转箭头(类似时钟的动画)

转载 作者:行者123 更新时间:2023-11-29 10:25:31 33 4
gpt4 key购买 nike

我想将此箭头旋转到时钟中的一个固定点。下面的代码没有做我打算做的事情,它将整个箭头旋转到圆心。我还尝试在圆形路径上设置动画,但它没有给我想要的效果......我想让这个箭头绕一个圆圈旋转,同时箭头指向这个圆圈的中心

-(void) addArrow2:(CGSize)size{
_Arrow2 = [SKSpriteNode spriteNodeWithImageNamed:@"arrow2"];
_Arrow2.position = CGPointMake(self.frame.size.width/2 , self.frame.size.height/2 +30);
SKAction *rotate = [SKAction rotateByAngle:M_2_PI duration:1];
SKAction *forever = [SKAction repeatActionForever:rotate];

_Arrow2.yScale = 0.45;
_Arrow2.xScale = 0.45;

[self addChild:_Arrow2];

[_Arrow2 runAction:forever];
}

最佳答案

我想你有这种箭头 →。将 anchorPoint 更改为 (1.0, 0.5) 并使箭头沿着圆形路径移动。进行一些更改以满足您的需要。

- (void)addArrow2
{
_Arrow2 = [SKSpriteNode spriteNodeWithImageNamed:@"arrow2"];
_Arrow2.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2+30);
_Arrow2.anchorPoint = CGPointMake(1.0, 0.5);
_Arrow2.yScale = 0.45;
_Arrow2.xScale = 0.45;

// Make a circle path
CGMutablePathRef circle = CGPathCreateMutable();
CGFloat centerX = self.frame.size.width/2;
CGFloat centerY = self.frame.size.height/2;
CGFloat radius = 25.0;
CGFloat startAngle = 0.0;
CGFloat endAngle = 2*M_PI;
CGPathAddArc(circle, NULL, centerX, centerY, radius, startAngle, endAngle, true);
CGPathCloseSubpath(circle);
SKAction *followPath = [SKAction followPath:circle asOffset:NO orientToPath:YES duration:2.0];

// Infinite rotation
SKAction *forever = [SKAction repeatActionForever:followPath];
[_Arrow2 runAction:forever];

[self addChild:_Arrow2];
}

动画预览:

enter image description here

关于ios - 向固定点旋转箭头(类似时钟的动画),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32528133/

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