SKButton不工作

时间:2015-03-28 14:37:29

标签: user-interface swift

所以我用SpriteKit以编程方式创建了一个按钮,但它认为按钮节点比按钮大。

这就是我所拥有的。

 override func didMoveToView(view: SKView) {
    let button = SKSpriteNode(color: SKColor.greenColor(), size: CGSizeMake(100, 44))
    button.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
    self.addChild(button)
}

 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)
        if button.containsPoint(location) {
            println("tapped")
        }
    }
}

当我运行游戏时,它允许我点击按钮,但它也会在按钮下方的任何位置检测到触摸。

0 个答案:

没有答案