我想从圆心画一个圆和一条线,它也是圆半径的两倍
我的输出是画一个圆旁边有一个圆。
- (void)setupMainBall {
mainBall = [self makeMainBall];
mainBall.position = CGPointMake(self.size.width / 2, self.size.height / 2);
mainBall.zPosition = 3;
[self addChild:mainBall];
[mainBall addChild:[self makeCanon]];
}
-(SKShapeNode *)makeMainBall {
SKShapeNode *theMainBall = [[SKShapeNode alloc] init];
CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddArc(myPath, NULL, 0, 0, 10, 0, M_PI*2, YES);
theMainBall.fillColor = [SKColor blueColor];
theMainBall.path = myPath;
theMainBall.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:theMainBall.frame.size.width / 2];
return theMainBall;
}
-(SKSpriteNode *)makeCanon {
canon = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(3, 20)];
canon.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:canon.frame.size];
return canon;
}
最佳答案
尝试:
SKSpriteNode *canon = [self makeCannon];
[mainBall addChild:canon];
canon.position = CGPointMake(mainBall.size.width / 2, mainBall.size.width /2);