问题描述
我查看了所有帖子,WWDC会谈和youtube视频,但我仍然无法弄清楚如何在不同级别拥有多个SKscenes并使用Spritekit将它们与游戏中的swift文件连接起来。我想要一个主级别板,如果你按下SKSpriteNode,我设法打开一个新的场景,但是我如何为这个特定的SKScene实现游戏逻辑?
如果这是一个愚蠢的问题请提前道歉,我已经花了很长时间。
I looked through all posts, WWDC talks and youtube videos, but I still can't figure out how to have multiple SKscenes for different levels and connecting them with swift files in a Game using Spritekit. I want to have a main level board and I managed to open a new scene if you press a SKSpriteNode, but how can I implement game logic to this specific SKScene?Apologies in advance if it is a silly question, I've been spending ages on it.
推荐答案
你可以这样做:
1)创建 .swift
文件并创建一个<$的子类c $ c> SKScene
1) Create .swift
file and make a subclass of a SKScene
转到:
并创建SKScene的子类
and make subclass of a SKScene
class MenuScene:SKScene {}
2)创建.sks文件
然后转到
并制作一个 MenuScene.sks
(将其命名为 MenuScene
,不带实际扩展名。)
and make a MenuScene.sks
(name it MenuScene
without the actual extension).
对您想要拥有的每个场景重复此步骤。
Repeat this steps for each scene you want to have.
然后加载并启动您的初始场景。在 GameViewController.swift
中执行此操作:
Then to load and start your initial scene. Do this inside your GameViewController.swift
:
if let scene = GameScene(fileNamed:"GameScene") {
let skView = self.view as! SKView
//setup your scene here
skView.presentScene(scene)
}
要转换到其他场景(假设您当前在 MenuScene
中),您应该执行以下操作:
To make a transition to other scene (lets assume that you are in the MenuScene
currently) you should do something like this:
if let nextScene = GameScene(fileNamed: "GameScene"){
nextScene.scaleMode = self.scaleMode
let transition = SKTransition.fadeWithDuration(1)
view?.presentScene(nextScene, transition: transition)
}
这篇关于如何将swift文件与SKscene连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!