简体   繁体   中英

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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM