As one might expect I'm new to Objective-C and Cocoa2d so this might be painfully obvious but I can't seem to get it to work in a way that makes sense.
What I'm trying to do is to make an array of 10 members (more will be added later) full of either [0,1,2,3] integers, later I want these numbers to be used for a level selection screen where 0 means the level is locked (not completed), and the numbers >0 represent the number of stars (out of three) and mean the level was completed, at the end of a level I want to change the array to reflect that the level was completed. For testing purposes I filled the array with "random integers" (0-3) as such (in LevelSelection.m
):
NSMutableArray *LevelCompArray = [NSMutableArray arrayWithCapacity:10];
for(int i = 0; i<10; i++){
int x= (arc4random() % (4));
[LevelCompArray addObject:[NSNumber numberWithInteger:x]];
}
I have not alloced nor init the Array but it seems to work within the function itself -(id) init
though I believe that is a the root of my problem.
My problem is simple, how do I transfer this array (and other data I will create as my game progresses) from class to class (e.g. from LevelSelection.m
to LevelCompleted.m
) and from function to function (e.g. -(id) init
and -(void) launchLevel
). Do I have a centralized file for data that all required classes can access? If that's the case what's with all the talk of a ".plist"? If not, do I transfer the data through methods to the target class(es)/ method(s)? How do I do that?
Any help is deeply appreciated, transferring me to a tutorial would also be incredibly useful.