所以我现在正在制作游戏。我有很多场景:菜单,设置,gameScene和GameOverScene。
ALMOST ALL场景之间的转换没有问题,我用来转换的代码是: (例如菜单到GameScene)
let secondScene = GameScene(size: self.size)
let transition = SKTransition.pushWithDirection(.Up, duration: 0.7)
secondScene.scaleMode = SKSceneScaleMode.AspectFill
self.scene!.view?.presentScene(secondScene, transition: transition)
然而,我的GameScene到GameOverScene是非常小故障。通常会有一段很长的停顿。
GameOverScene的全部内容是:
import Foundation
import SpriteKit
class GameOverScene: SKScene {
override func didMoveToView(view: SKView) {
let myLabel = SKLabelNode(fontNamed:"American Typrewriter")
myLabel.text = "Game Over!";
myLabel.fontSize = 45;
myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));
self.addChild(myLabel)
}
}
因此,我认为这不太可能是推迟转型的原因。
我用来调用'游戏结束'的代码是:
override func update(currentTime: CFTimeInterval) {
if sprite.position.y < 100 {gameOver()}
}
func gameOver() {
// Loads GameOver Scene //
let secondScene = GameOverScene(size: self.size)
// Creates vibration //
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
func boatSink() {
sprite.physicsBody = nil
sprite.physicsBody?.affectedByGravity = false
sprite.physicsBody?.dynamic = false
let spritefly = SKAction.moveTo(CGPointMake(400,20), duration:2.0)
car.runAction(spritefly) }
let transition = SKTransition.pushWithDirection(.Up, duration: 3.0)
let nextScene = GameOverScene(size: scene!.size)
nextScene.scaleMode = .AspectFill
scene?.view?.presentScene(nextScene, transition: transition)
}
我已尝试使用延迟,例如使用:
let skView = self.view! as SKView
let scene = GameOverScene(size: self.scene!.size)
scene.size = skView.bounds.size
scene.scaleMode = .AspectFill
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 1 * Int64(NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {
let sceneTransition = SKTransition.doorsCloseHorizontalWithDuration(2.0)
sceneTransition.pausesOutgoingScene = true;
skView.presentScene(scene, transition: sceneTransition)}
要加载时间,但这不起作用。
我也试过使用'pausesOutgoingScene'和暂停IncomingScene'无济于事。
我终于尝试使用以下方法将当前场景减速到0.0
func pauseGameScene() {
self.physicsWorld.speed = 0.0
self.speed = 0.0
}
虽然这只会阻止代码继续前进。
我的问题是: 有没有什么东西真的很明显,我没有考虑过我的过渡? 2.有没有办法提前加载所有场景,我相信这可能只会提供微小的改进,但它绝对是一个我还没有看过的领域。