Creating a game without using SpriteKit

I have an idea for a game that does not require any SpriteKit features, such as (physics, collision, or action). This is a simple strategy game, itโ€™s kind of like (Plague Inc, or Democracy) of you guys familiar with these games, so I decided that I could make it easy for myself and just create it in the usual way with the luxury of using Storyboard viewControllers and an object instead to do all this in code. But there is one feature of SpriteKit that will be very important for my game (or any game, for that matter), which is not built in regular Xcode projects, which are the "Update" method, which you know to track ratings and other values, therefore I implemented something close to it and it works great:

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 fine, but I'm not sure if this is the best practice or how much such a method will affect application performance, especially if I have more than one method that works all the time.

+7
ios swift sprite-kit
source share
4 answers

I created games with and without SpriteKit, and what you do is great.

You may need to check the account wherever you update the account. If the score is updated in more than one place, call the function that updates the score and then immediately checks it. Then you can avoid the cycle all together. In addition, if the counter is updated several times before the cycle starts, it may skip the case where the score == 10.

+6
source share

With the current code, you call the check() function every second. This whole function compares an integer. This is one of the simplest things a computer can do: a processor on an iOS device can perform many thousands of such comparisons in much less time than a second. Therefore, you have no reason to worry.

Now that you have created your game, you may find that you are expanding and adding things to this method, in which case performance may become a problem. The best thing you can do is make one of the above comments, just build your game and see if it becomes a problem. Itโ€™s always good to think about performance, but at the same time it can be bad to optimize when you donโ€™t need it.

+2
source share

Just leaving your description, you should be fine with it in UIKit. SpriteKit is designed for high-performance games that require more processing power than your simple card game. The types of games you are talking about are Not High Performance. Most of the processing power comes from the number of crunching in your simulation, but that's really about it.

If you need something like an update for points, you can just use a simple file file or something like that. You can also try using a timer, but I think using a simple didSet would be a simple solution, as it automatically changes when you get and set the variable. If I add one to the variable, Xcode will automatically update the score for me using didSet. I do not know all the details of your game, so try first in UIKit (takes less time). If it slows down, go to SpriteKit.

I will link the documents with didSet for you. If you are reading a document type, try hacking WithSwift. Both options are good:

"willSet is called immediately before the value is saved. The didSet function is called immediately after the new value is saved.

if you want to read more, click on the link ...

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html

0
source share

override func viewDidLoad () super.viewDidLoad () // Perform any additional configuration after loading the view

0
source share

All Articles