以下代码在didBeginContact()
中调用let retryButton = SKShapeNode(rectOfSize: CGSize(width: 100, height: 100))
retryButton.position = CGPoint(x: self.frame.width / 2 - 100, y: self.frame.height / 2 - 200)
retryButton.strokeColor = UIColor.redColor()
retryButton.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: 100, height: 100))
retryButton.name == retryButtonName
worldNode.addChild(retryButton)
以下是我的touchesBegan()的样子
let touch = touches.first! as UITouch
let touchLocation = touch.locationInNode(worldNode)
let body: SKPhysicsBody? = self.physicsWorld.bodyAtPoint(touchLocation)
if body?.node?.name == retryButtonName {
let scene = GameScene(size: self.size)
self.view?.presentScene(scene)
print("retry button is pressed")
}