I have a game idea in mind that doesn't require any of the SpriteKit features like (physics, collisions or actions) it's a simple strategy game something like ( Plague Inc , or Democracy ) of you guys are familiar with those games. So i figured i could make it easy for myself and just create it the normal way with the luxury of using Storyboard viewControllers and object instead of doing all this in code. But there is one feature SpriteKit has that would be very essential to my game( or any game for that matter ) that is not build in the normal Xcode projects which is the "Update" method, you know for keeping track of score and other values, so i implemented something close to it and works just fine:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var finish = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "check", userInfo: nil, repeats: true)
}
func check() {
if score == 10 {
println("Win!")
}
}
This works just fine but i'm not sure if this is the best practice or how much will a method like this will affect the performance of the app, especially if i have more than 1 method that runs all the time .
I've created games with and without SpriteKit, and what you're doing is perfectly fine.
You may want to consider checking the score wherever you're updating the score. If the score gets updated in more than one place, then call a function that updates the score and then immediately checks it. Then, you can avoid the loop all together. Also, if the score gets updated multiple times before the loop runs, it may skip the case where score == 10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With