我无法通过触摸场景上的按钮来加载新场景。 按钮名为:BuStartGame 要加载的场景:CategoriesScene 场景加载类:CategoriesSceneClass。
这是我的代码。
import Foundation
import SpriteKit
import GameplayKit
import UIKit
class GameScene: SKScene {
override func touchesBegan(_ touches: Set<UITouch>, with event:UIEvent?){
for touch in touches {
let location = touch.location(in: self);
//Mark: ===================== StartGame
if atPoint(location).name == "BuStartGame"{
if let scene = CategoriesSceneClass(fileNamed:"CategoriesScene"){
scene.scaleMode = .aspectFill
view!.presentScene(scene, transition: SKTransition.doorsOpenVertical(withDuration: 2))
}
}
}
}
}
编辑: 我发现问题出在这段代码中。当我删除 IF 时它可以工作,但作为一个按钮可以工作整个场景。
if atPoint(location).name == "BuStartGame"{
最佳答案
去年我在 SpriteKit 中玩了一个演示游戏,这里是一些我用于类似按钮转换的代码,下面将类名和文件名更改为你的。尝试在“if let scene”部分中替换它。
if let scene = CategoriesSceneClass(fileNamed:"CategoriesScene") {
// Configure the view.
let skView = self.view!
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = false
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene, transition: SKTransition.doorsOpenVertical(withDuration: 2))
关于ios - 无法通过触摸按钮加载新的 SpriteKit SKScene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48659503/