我刚刚更新到 xCode beta 6。在 beta5 中一切正常,但在 beta 6 中必须改变一些东西。我加了很多“!” 在我的代码中。无论如何,我的项目是小游戏。完成关卡(赢或输)后,我想调用 skscene。
代码在 mainviewController 中:
if(flag==true){// IF we WON
/* That below lines should call "Won.swift" file But it doesn't */
var scene = Won(fileNamed: "GameScene")
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = SKSceneScaleMode.AspectFill
scene.position = CGPointMake(0, 568)
skView.presentScene(scene)
}
Won.swift 文件是:
class Won: SKScene {
var audioPlayer = AVAudioPlayer()
override func didMoveToView(view: SKView) {
/* Setup your scene here */
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Fireworks", ofType: "mp3")!)
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound2, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
let myLabel = SKLabelNode(fontNamed:"Chalkduster")
myLabel.text = "You Win";
myLabel.fontSize = 65;
myLabel.fontColor = UIColor.redColor()
myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));
self.addChild(myLabel)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
此代码在 beta 5 中有效,但在 beta6 中无效。此外,我将 uikit、avfoundation、spritekit 基础重新添加到项目中。并检查媒体文件“mp3”或图像是否存在于捆绑资源中......该项目运行完美,没有任何错误或警告。但是 Skscene 部分不起作用。我还尝试设置断点来跟踪它的运行方式。该过程继续进行,但从未进入“Won.swift”文件。
有什么建议吗?谢谢你。