我正在编写IOS GAME应用程序而不是单个视图或空白视图..
好的所以我试图通过将此代码放入我的appDelagate.swift
来首先检测第一次启动女巫我能够做到没有问题import UIKit
import SpriteKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")
if launchedBefore{
print("Has launched before")
}
else
{
print("First launch")
}
return launchedBefore
}
好了,现在我怎么准确地使用这段代码打开一个menue屏幕一次?我无法在任何地方找到答案.. 我的gameViewControler.swift看起来像每个应用程序运行这个" FirstMainMenuScene"打开..然而我希望它只在第一个lauch和otherwize opeh打开只是普通的老" MainMenuScene"
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Load 'GameScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
let scene = FirstMainMenuScene(size: CGSize(width: 1536, height: 2048))
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
现在我已经尝试了我能想到的所有内容,例如输入if语句并计算应用程序打开的次数 " var numberOfRuns = 0" 然后把柜台放进去 " numberOfRuns + = 1" 然后做if语句 "如果numberOfRuns> = 1 {//打开我想要的第一页// else {//打开真实应用页面" 但我把它全部拿出来因为它不起作用 所以我的问题是..我如何实现这个检测第一次运行代码,我把它放在appDelaget.swift ???? 有人请帮助我,我被困了几个小时!!!!!
答案 0 :(得分:0)
确定已解决!问题是appDelagate.swift ..我完成了它默认并把dectect第一次运行代码放在主storyboard.swift我认为这是因为我选择了游戏而不是空白活动!这是代码,如果有人来找我,需要帮助! 导入UIKit 导入SpriteKit 导入GameplayKit
类GameViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")
if launchedBefore{
print("Has launched before")
// Load 'GameScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
let scene = MainMenuScene(size: CGSize(width: 1536, height: 2048))
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}
else
{
print("First launch")
// Load 'GameScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
let scene = FirstMainMenuScene(size: CGSize(width: 1536, height: 2048))
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
UserDefaults.standard.set(true, forKey: "launchedBefore")
}
}