无论如何,这里是我如何得到好的结果:
只需打开一个新项目并尝试以下操作:
在您的 GameViewContrller 而不是使用viewDidLoad使用viewWillLayoutSubviews。
编辑:这是Rob Mayoff 对viewDidLoad和viewWillLayoutSubviews等方法的一个很好的解释。
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;
// Create and configure the scene.
if(!skView.scene){
GameScene *scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
所以现在在场景类的 didMoveToView 方法中,画一条线:
SKShapeNode *yourline = [SKShapeNode node];
CGMutablePathRef pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, 0.0, 0.0);
CGPathAddLineToPoint(pathToDraw, NULL, self.frame.size.width,self.frame.size.height);
yourline.path = pathToDraw;
[yourline setStrokeColor:[UIColor redColor]];
[self addChild:yourline];
CGPathRelease(pathToDraw);
阅读有关init 与 didMoveToView 的文章(阅读 LearnCocos2D 发表的评论)。
差不多就是这样,我希望它有所帮助。