iPhone 5s SpriteKit绘图怪异

据我所知,iPhone 5s的像素分辨率为640 x 1136,分辨率为320 x 568(为了与非Retina设备兼容)。

当我使用SpriteKit时,问题/混乱/怪异似乎出现了。 例:

我从左下angular(0,0)到右上angular(宽度,高度)绘制一条线。 结果是这条线几乎中途被吸引了。 而事实上,当我打印出来的屏幕尺寸,它应该是320×568。所以我决定从(0,0)到(宽* 2,高* 2)绘制。 当然,这个打印出640 x 1136。

所以奇怪的是,即使我正在从一个对angular线angular落画angular,但实际上并不是从一个angular落到另一个angular落。

笔记:

- I'm getting the width & height values from self.value.frame.size. - The diagonal line seems to draw just fine using any of the iPad simulators. 

有什么想法发生在这里? 在这里输入图像说明

反正这里是我如何得到好的结果:

只要打开一个新的项目,试试这个:

在您的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]; } } 

所以现在在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 vs didMoveToView的内容(阅读LearnCocos2D发表的评论)。

所以这是非常多的,我希望它有帮助。