无法将精灵添加到场景中

时间:2014-12-18 01:48:35

标签: ios objective-c sprite-kit

我不明白为什么不让我把球加到现场。下面的代码是我正在使用的唯一代码。

-(void) addBall:(CGSize)size {
ball = [SKShapeNode shapeNodeWithCircleOfRadius:50];
ball.color = [SKColor colorWithRed:225.0f/255.0f green:76.0f/255.0f blue:76.0f/255.0f alpha:1.0];
ball.position = CGPointMake(self.size.height/2, self.size.width/2);

[self addChild:ball];
}

-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */

[self addBall:size];
}

1 个答案:

答案 0 :(得分:1)

enter image description here

-(void) addBall 
{
    SKShapeNode *ball;
    ball = [SKShapeNode shapeNodeWithCircleOfRadius:50];
    ball.strokeColor = [SKColor colorWithRed:225.0f/255.0f green:76.0f/255.0f blue:76.0f/255.0f alpha:1.0];
    ball.fillColor = [SKColor colorWithRed:225.0f/255.0f green:76.0f/255.0f blue:76.0f/255.0f alpha:1.0];
    ball.position = CGPointMake(self.size.height/2, self.size.width/2);

    [self addChild:ball];
}

-(void)didMoveToView: (SKView *)view
{
    [self addBall];
}

这是有效的,我测试了。