I'm brand new to SpriteKit, and I'm creating a game that involves randomizing the CGPoint positions of objects on my screen when the user reaches certain score increments. I created a plist of the 8 set positions I want my objects to choose from when this method is called, but I'm having a problem with my objects selecting duplicate plist positions and overlapping each other. Is there a method I can call that will prevent my objects from picking the same position from the plist as another object when that method is called?
FYI, I plan on calling this randomization method many times throughout the course of the game.
I wrote the following code but my game crashes.
- (NSMutableArray *)pickAndRemoveFromList:(NSMutableArray *)list {
list = [_objectList copy];
NSInteger randomIndex = arc4random()%list.count;
Objects *object = [list objectAtIndex:randomIndex];
[list addObject:object];
[list removeObject:object];
return list;
}