如何让我的SKLabelNode成为在SpriteKit中呈现新视图的元素?

时间:2018-06-07 16:58:25

标签: ios swift sprite-kit

class GameScene: SKScene {
class LabelButton: SKLabelNode {
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch: AnyObject in touches {
            let location = touch.atPoint(position)
            if self.contains(location) {
                print ("nothing")
            }
        }
    }
}



override func didMove(to view: SKView) {
    let nothing = LabelButton(fontNamed: "San Francisco")
    nothing.text = "nothing?"
    nothing.fontColor = SKColor.white
    nothing.fontSize = 20
    nothing.position = CGPoint(x: 200, y: 200)
    addChild(nothing)
}

func goToPlanetNothing(){
    var gameScene1 = PlanetNothing0(fileNamed: "PlanetNothing0")


    let transitionEffect =
        SKTransition.flipHorizontal(withDuration: 1.0)
    gameScene1 = PlanetNothing0(size: (gameScene1?.size)!)
    gameScene1?.anchorPoint = CGPoint(x: 0.0, y: 0.0)
    gameScene1?.view?.presentScene(gameScene1! , transition:transitionEffect)
}

这是代码。如果我去模拟器,我点击元素,但没有任何反应。但是,代码不会崩溃或显示错误。

1 个答案:

答案 0 :(得分:1)

touchesEnded()内填写此内容:

for touch in touches {
    if self.contains(touch.location(in: self.scene!)) {
        print("nothing")
    }
}