如何使用 swift 以编程方式将按钮添加到 sprite-kit?

How to add a button to sprite-kit programmatically with swift?

我想在 sprite-kit 中以编程方式添加一个按钮 直到现在我才能够做到这一点:

这就在 class 之后:

var button: SKNode!

然后在 didMoveToView 方法中我有这个:

button = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 100, height: 44))
button.position = CGPoint(x: CGRectGetMaxX(frame), y: CGRectGetMaxY(frame))
addChild(button)

按钮未显示,因为它的位置。

例如,写

button.position = CGPoint(x: size.width / 2, y: size.height / 2)

按钮出现在 SKScene 的中心。