gpt4 book ai didi

Sprite Kit 中的 iOS 圆圈和线条

转载 作者:行者123 更新时间:2023-11-29 03:14:26 26 4
gpt4 key购买 nike

我想画一个圆和一条从圆心开始的线,它的长度也是圆半径的两倍

我的输出是画一个圆,旁边有一条线。

- (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);

关于Sprite Kit 中的 iOS 圆圈和线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21841860/

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