当前位置: 动力学知识库 > 问答 > 编程问答 >

sprite kit - Swift + Spritekit Problems positioning node

问题描述:

For some reason I cannot seem to get these two nodes to position themselves correctly.

I have one node that I want to be centered:

 shape1.path = UIBezierPath(

roundedRect: CGRect(x: -128, y: -128, width: 256, height: 50),

byRoundingCorners: [.BottomLeft, .BottomRight],

cornerRadii: CGSize(width: 20, height: 20)).CGPath

shape1.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame) + 100)

shape1.fillColor = UIColor.whiteColor()

shape1.zPosition = -8

That works fine. The second node however is the one that I am having the problems with.

I am trying to get the node to position directly underneath:

let alertShapeNoButton = SKShapeNode(rectOfSize: CGSize(width: 256, height: 50))

shape2.fillColor = SKColor.redColor()

shape2.position = CGPoint(x:shape1.position.x , y:shape2.position.y)

However, the result is (Red is Shape2, which I want below):

Can anyone tell me why this is happening and how to fix?

分享给朋友:
您可能感兴趣的文章:
随机阅读: