HelloimDarius
HelloimDarius

Reputation: 705

Node's data in Sprite Kit

For the moment, I save all my nodes data using UserData, but I often hear that I should use some sort of separate class. And I cant figure out how to use it. I have multiple nodes with their data, like hp, attack damage, and so on. And how would I retrieve data for the correct node? Any input would be helpful. Thanks!

Upvotes: 1

Views: 75

Answers (2)

sangony
sangony

Reputation: 11696

Subclass your node and create your desired properties for each class. There are numerous examples on how to do this posted on SO.

Upvotes: 0

Greg
Greg

Reputation: 25459

I would recommended you to use a plist.

You could create a plist file with the data you want to save, for example: nodeType, hp, attack, etc. When you initialise the game load the plist, read it and base on the nodeType value you can set up the node in code, for example nodeType 1 is your hero, 2 is your enemy, etc.

Upvotes: 3

Related Questions