Change in background, characters, ETC.

Hi,


does anybody know a good link or source to where I can learn and find out how to have a customization page for my game? For example to change from one spaceship to another (Meaning changing characters from blue, to red, ETC.) To change the background of the game too. How would I do that? Also, how do I make some locked until the user completes something?


Thanks,


Julian

Replies

I teach just about every thing related to Sprite Kit at my website. I've read some of your other posts recently (replied to them too) and I think my free beginner course would help you a lot.

What is your website?

?

I'll give you a hint, its appeared twice in this forum already.

I cannot find it. Can you please post a link?

Ok I think I found it. Where do I go to see the background and customization tutorial? Also, how do I make some customization features locked until the user completed some sort of task?

First you would write the code to do the customizations, and then you would disable that functionality if they hadn't completed the task / purchased an upgrade in your app. UIButtons have a .isEnabled property (or maybe isUserInteractionEnabled). It's google-able.


And I read your question identical to this in another forum. Its just such a general question, you're not going to get anything but really general answers. Its a bit like asking "how to use Xcode". You aren't going to get a lengthy answer.


What you need to do is start writing your code for this, then come back when you've really hit a roadblock. Snippets of code you are stuck on is a good way to get some very specific help.

The problem I am having is how to write that code. I don't know how to tranfer the user to another .swift file which will contain the same game data, but just a different background. That is why I created this fourm, to get help and input on how to do this.

?

Well there's all sorts of ways to save data but this sounds specifically like a job for the user preferences. So you want to look into the Standard User Defaults. Declared like so ...


let defaults:UserDefaults = UserDefaults.standard


You would want to declare this in any of your Swift files that save or read from the defaults.


So in your main code, you can save to the defaults like so...


self.defaults.set( "red" , forKey: "BackgroundColor")


Perhaps someone clicks a red button, so the defaults now has a key named BackgroundColor equaling "red"


Then access them from anywhere else like so...


let theColor:String = defaults.object(forKey: "BackgroundColor")


And depending on what kind of value you are saving that line might vary. For example...


let someNumber:Int = defaults.integer(forKey: "BackgroundColor")


The beauty of the Standard User Defaults is that as long as the user doesn't delete the app, this data persists. So months later they might come back to the app, and if they changed the background color previously, you can code the app to search for a previously saved default key, and if one exists, adjust the color accordingly. So you'll do things like this when the app launches...


if ( defaults.object( forKey: "BackgroundColor") != nil) {
// do something with the object for the key because one exists
}


Just remember once you start saving to the defaults, you'll need to reset the Simulator (or delete the app from the Simulator) or delete the app from your test device to clear out those defaults.