am having game with 10 levels. i want to change the second level lock image to unlock when first level is completed.
am using 20 images ( 10 locked and 10 unlocked).
am using cc menus to display the number images.
for example(code):-
CCMenuItemImage *startButton12 = [CCMenuItemImage itemFromNormalImage:@"ten_new-lock.png"
selectedImage:@"ten_new-lock.png" target:self
selector:@selector(ten:)];
menu1 = [CCMenu menuWithItems: startButton3,startButton4,startButton5,startButton6,startButton7,startButton8,startButton9,startButton10,startButton11,startButton12, nil];
menu1.position = ccp(240,30);
[menu1 alignItemsHorizontally];
[menuLayer1 addChild: menu1];
am using below code for remember the level completed.
int lastLevelCompleted= [[NSUserDefaults standardUserDefaults] integerForKey:@"levelCompleted"];
if(currentLevel >lastLevelCompleted){
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:currentLevel forKey:@"levelCompleted"];
**now, how to change the lock to unlock images.
( if am doing here wrong)there is other way to solve means provide that. i have to implement that one.**
I have the same idea in one of my games. I solved it with separate lock and done icons that I have positioned on top of each menu item that represents a level.
Just create your menu items normally. Don’t try to represent locked or done states with the menu item’s icon. Instead create a smaller locked and done icons that you will instantiate as sprites and position on top of each menu item.
Here is the relevant part of my menu layer’s init method (I’m using a sprite atlas to store all my images):
and my helper method badgeIconFromFrame looks like this: