2

我有一个要在场景中心绘制的椭圆

 let center = (view.scene.position.x, view.scene.position.y)
 let size = (view.scene.frame.size.width * 0.7, view.scene.frame.size.height * 0.7)
 let ellipse = SKShapeNode (ellipseInRect: CGRectMake(center.0, center.1, size.0, size.1))
 ellipse.strokeColor = UIColor.blackColor()
 ellipse.position = CGPointMake(center)
 self.addChild(ellipse)

但它出现在场景中,如下所示:

密景

我如何将它定位在场景的中心?

4

1 回答 1

3

Instead of using

let ellipse = SKShapeNode (ellipseInRect: CGRectMake(center.0, center.1, size.0, size.1))

use

let ellipse = SKShapeNode (ellipseOfSize: CGSizeMake(size.0, size.1))

And center the sprite around

let center = (CGRectGetMidX(view.scene.frame), CGRectGetMidY(view.scene.frame))
于 2014-06-15T01:54:46.573 回答