我在按下按钮时尝试切换场景,但是,当我点击它时,没有任何反应,也没有任何内容被打印出来。没有错误,我只是想知道它为什么不起作用。 我编程的节点显示在正确的大小和位置,但当你点击它时,没有任何东西通过。谢谢你的帮助。
代码:
class LevelScene: SKScene, SKPhysicsContactDelegate {
var isFingerOnBlock = false
let LevelOneName = "levelOne"
override func didMove(to view: SKView) {
super.didMove(to: view)
let Pineapple = SKSpriteNode(imageNamed: "ball")
Pineapple.isUserInteractionEnabled = true
Pineapple.position = CGPoint(x: self.frame.midX - 200, y: self.frame.midY);
Pineapple.name = "pineapple"
addChild(Pineapple)
}
func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
let touch = touches.anyObject() as! UITouch
let location = touch.location(in: self)
let nodes = self.nodes(at: location)
for node in nodes
{
if node.name == "pineapple"
{
print("ceeds")
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view!
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .aspectFit
skView.presentScene(scene)
}
break
}
}
}
}
答案 0 :(得分:0)
您已宣布
func touchesBegan(touches: NSSet, withEvent event: UIEvent)
该签名没有内置功能,你从不调用该功能;因此你的函数从不调用。
答案 1 :(得分:0)
谢谢马特!我修复了我的代码:它现在有效..
override func touchesBegan(_ touches: Set<UITouch>,
with event: UIEvent?) {
let touch = touches.first!
let location = touch.location(in: self)
let node : SKNode = self.atPoint(location)
if(atPoint(location) == node){
if node.name == "levelOne" {
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .aspectFit
skView.presentScene(scene)
}
}
}
}