Reputation: 191
I am trying to make a game in SpriteKit and one of the features that I would like to have is a progress bar. I have done a lot of research and people are saying to use an 'SKCropNode' however I have failed to find any code as to how to do this in swift.
And so I am wondering how I should go about making a progress bar and any example code would be very useful.
Upvotes: 1
Views: 1407
Reputation: 3597
I suggest that you use a colored SKSpriteNode and gradually make it longer as the 'progress bar' progresses. This is safer than using a UIProgressView because a UIProgressView a) uses a different coordinate plane than Sprite kit and b) does not follow the same rules as an SKSpriteNode. For example, it may not be removed when the scene changes whereas an SKSpriteNode would be removed.
Upvotes: 4
Reputation: 305
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
Upvotes: 1