I'm wondering if anyone has suggestions for how to manage the positioning of many sprites in pre-set and complicated patterns? Currently the brute-force method is to painstakingly code each sprite into its place. However, ideally, I would like to not have to code it directly, but instead read the sprite positions in from a file (or some other data source). Are there any solutions out there that do this?
closed as off-topic by Anko, bummzack, congusbongus, Seth Battin, MrCranky Aug 13 '14 at 13:06
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – bummzack, Seth Battin, MrCranky
You're on iOS using Objective-C, I assume, so use PLIST files.
XCode has an excellent PLIST editor. NSDictionary lets you load a PLIST file with a single method call:
NSDictionary * plistDict = [NSDictionary dictionaryWithContentsOfFile:@"test.plist"];
From that, it is very easy to automate. Just load the dictionary and set the sprite position:
double x = [[plistDict objectForKey:@"sprite_pos_x"] doubleValue]; double y = [[plistDict objectForKey:@"sprite_pos_y"] doubleValue]; sprite.position = ccp(x,y);
If you change the sprite position in the PLIST, there is no need to recompile. With a bit of work, you can even add runtime reloading of modified files.