我想在时钟的固定点上旋转此箭头。下面的代码没有做我打算做的事情,它将整个箭头旋转到圆心。我也尝试在圆形路径上制作动画,但它没有给我我想要的效果...... 我希望这个箭头围绕一个圆圈旋转,而箭头指向这个圆圈的中心
-(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];
}
答案 0 :(得分:2)
我想你有这种箭头→。将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];
}
动画预览: