我在LevelSelect
图层中正确加载pList图像时遇到问题。这是CCScrollLayer
,有2页和20个菜单项。
我遇到的问题是,当我第一次运行我的项目时,它显示所有未锁定的内容,当我返回主菜单并返回级别选择图层时,我可以看到所有内容都完全锁定,因为它应该在第一次尝试中完成。
我无法弄清楚它究竟出了什么问题。
这是我的菜单项代码:
NSString *string2 = [NSString stringWithFormat:@"Level2"];
dictionary = [plistData objectForKey:string2];
CCMenuItemSprite *l2 = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:@"sd2On.png"]
selectedSprite:[CCSprite spriteWithSpriteFrameName:@"sd2Off.png"]
target:self
selector:@selector(levelGame2:)];
l2.scale = 0.6;
CCMenu *menu2 = [CCMenu menuWithItems: l2, nil];
menu2.position = ccp(160,200);
[pageOne addChild: menu2];
int blocked = [[dictionary valueForKey:@"Block"] intValue];
int stars2 = [[dictionary valueForKey:@"Stars"] intValue];
if(blocked){
// 11. Load image with padlock
CCSprite *overlaySprite = [CCSprite spriteWithSpriteFrameName:@"lockLevel.png"];
// Place the image of the lock
overlaySprite.position = ccp(63, 60);
// 12. disable the level
l2.isEnabled = NO;
// 13. add the image of the padlock to the item that already contains an image and a text
[l2 addChild:overlaySprite z:100];
}else{
NSString *starsString2 = [NSString stringWithFormat:@"star%d.png",stars2];
CCSprite* starsImage2 = [CCSprite spriteWithSpriteFrameName:starsString2];
starsImage2.position = ccp(60, 10);
starsImage2.scale = 0.8;
[l2 addChild:starsImage2];
}
和使用pList
NSString *filename = @"Chapter1";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
// Apre il file plist
path = [[NSBundle mainBundle] bundlePath];
finalPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist", filename]];
plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
success = [fileManager fileExistsAtPath:finalPath];
if (!success) {
path = [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"];
success = [fileManager copyItemAtPath:path toPath:finalPath error:&error];
[fileManager copyItemAtPath:path toPath:documentsDirectory error:&error];
}