2016-02-25 80 views
0

我希望在我的應用中使用progress bar來表示一個百分比。UIProgressView - 進度條 - SpriteKit/Swift

我用斯威夫特實際構建它Spritekit,所以我希望以編程方式做到這一點,而無需使用故事板等

我發現this awesome tutorial的,但不幸的是我似乎無法添加它到我的GameScene/worldNode ...

如何創建一個進度條並將其添加到我的GameScene,在我的SKView/Gamescene(不通過ViewController)?

回答

0

那麼,你可以使用UIKit來製作一個進度條。我相信,UIKit是使用SpriteKit導入的,但如果不是,您可以隨時導入它。你會想用UIProgress類,使進度條:

let prog = UIProgressView(frame: CGRectMake(your coordinates...)) 
//Set progress properties here (could also add a UILabel to show percentage from `progress` property 
self.view.addSubview(prog) 
0

進度條需要被放置在場景中的SKView。如果您沒有其他處理方式,您可以通過scene.view訪問它。

這裏是在操場的例子:

//: Playground - noun: a place where people can play 

import SpriteKit 

let view = SKView(frame: CGRect(x: 0, y: 0, width: 400, height: 300)) 
let scene = SKScene(size: view.frame.size) 
view.presentScene(scene) 

let progressView = UIProgressView(progressViewStyle: UIProgressViewStyle.Default) 
progressView.center = CGPoint(x: 200, y: 150) 

view.addSubview(progressView) 
// alternately scene.view.addSubview(progressView) 

progressView.progress = 0.5 
view 
+0

這是放置詮釋他的ViewController?因爲這樣就很難從遊戲場景更新......? – Reanimation

+0

這是一個操場。它沒有放置在任何特定的地方。 (例如,最後的'view'行不是你通常在代碼中看到的東西。)在Xcode中,'File-> New-> Playground'並粘貼所有代碼。 – bshirley