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)
}
这是代码。如果我去模拟器,我点击元素,但没有任何反应。但是,代码不会崩溃或显示错误。
答案 0 :(得分:1)
在touchesEnded()
内填写此内容:
for touch in touches {
if self.contains(touch.location(in: self.scene!)) {
print("nothing")
}
}