触摸SKShapeNode不起作用

时间:2015-09-14 10:45:09

标签: ios swift sprite-kit

以下代码在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")
}

0 个答案:

没有答案
相关问题