SKShapeNode使用错误的宽度和高度

最近我一直在创造一个游戏,在屏幕上放置圆圈。 不过,我注意到通告不是圆圈,而是椭圆。 y轴被拉伸的x轴已经缩小了。 为了弄清楚这个问题,我现在正在试图用一个矩形进行debugging。 我做矩形有相同的高度和宽度(方形),但是,当变成skshapenode它不再是正确的形状。 代码:

var testSquare = CGRect(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame), width: 1, height: 1) var squareNode = SKShapeNode(rect: testSquare) println(testSquare.width) println(testSquare.height) println(squareNode.frame.width) println(squareNode.frame.height) self.addChild(squareNode) 

这是从这里打印的:

 1.0 1.0 513.5 385.5 

如果我将testSquare的高度和宽度都更改为100,则这是打印的内容:

 100.0 100.0 612.5 484.5 

出于某种原因,x中squarenode的框架增加了512.5,在y中增加了384.5。 屏幕上出于某种原因,创build的矩形在Y中的长度更长。 也许框架不是我应该打印的数字,但不pipe屏幕上的形状是不是一个正方形。 有谁知道这是为什么? 任何帮助是极大的赞赏!

你使用sks文件来制作你的SKView吗? 或者你在viewcontroller中实例化它? 重要的是让你的场景的尺寸正确。 我知道这不是直接回答你的问题,但如果你得到奇怪的伸展和东西,也许你应该从这里开始,并从那里debugging..

这给了我正确的场景尺寸。

 override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) // Configure the view. let skView = self.view as SKView skView.showsFPS = true skView.showsNodeCount = true /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ let scene = GameScene(size: skView.bounds.size) scene.scaleMode = .AspectFill skView.presentScene(scene) }