0

I'm hoping to use a progress bar to denote a percentage in my App.

I'm actually building it in Spritekit using Swift, so I'm hoping to do it programmatically, without the use of a storyboard etc.

I found this awesome tutorial, but unfortunately I can't seem to add it to my GameScene/ worldNode...

How can I create a progress bar and add it to my GameScene, inside my SKView/Gamescene (not via ViewController)?

Reanimation
  • 3,151
  • 10
  • 50
  • 88

2 Answers2

0

Well, you could use UIKit to make a progress bar. UIKit, I believe, is imported with SpriteKit but if it's not you can always import it. You'd want to make the progress bar using UIProgress class:

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)
brimstone
  • 3,370
  • 3
  • 28
  • 49
0

The progress bar needs to be placed in the SKView of the scene. You can access it via scene.view if you don't otherwise have a handle on it.

Here's an example in a playground:

//: 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
bshirley
  • 8,217
  • 1
  • 37
  • 43
  • Is this placed int he ViewController? Because then it makes it difficult to update from the Game scene...? – Reanimation Feb 25 '16 at 22:21
  • This is a playground. It's not placed in anyplace particular. (for example, the last `view` line is not something you'd normally see in code.) In Xcode, `File->New->Playground` and paste all the code into that. – bshirley Mar 01 '16 at 20:29