我是 iOS 的 Sprite Kit 新手。我想在我的场景中添加一个形状节点。场景是灰色的,形状是场景中心的一个白色圆圈。我的场景代码如下。由于某种原因,将节点添加到场景的最后一行导致节点计数增加了 2。如果我不考虑那条线,就会有 0 个节点,只有一个灰色的场景。但是如果我离开这条线,那么圆圈就在那里,但节点数为 2。这是一个大问题,因为当我向圆圈中添加更多节点时,节点数是应有的两倍,并且会减慢速度。有谁知道问题是什么?非常感激!
@interface ColorWheelScene()
@property BOOL contentCreated;
@end
@implementation ColorWheelScene
- (void)didMoveToView:(SKView *)view {
if(!self.contentCreated) {
[self createSceneContents];
self.contentCreated = YES;
}
}
- (void)createSceneContents {
self.backgroundColor = [SKColor grayColor];
self.scaleMode = SKSceneScaleModeAspectFit;
SKShapeNode *wheel = [[SKShapeNode alloc]init];
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(0.0, 0.0)];
[path addArcWithCenter:CGPointMake(0.0, 0.0) radius:50.0 startAngle:0.0 endAngle:(M_PI*2.0) clockwise:YES];
wheel.path = path.CGPath;
wheel.fillColor = [SKColor whiteColor];
wheel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:wheel];
}
@end