我正在編寫一個cocos2d遊戲,在大多數遊戲中,您必須先完成前一級以繼續進入下一級。每個級別都在不同的層(節點)。我想將整數(1-20)存儲到屬性列表中,以便在整個遊戲中保留變量。是的,我一直在搜索互聯網約一個小時,找不到任何東西。將變量存儲在屬性列表文件中Cocos2d
我發現了一個代碼來存儲變量,但我不知道如何正確使用它。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *path = [documentPath stringByAppendingPathComponent:@"levelscompleted.save"];
NSMutableDictionary* myDict = [[NSMutableDictionary alloc] init];
myDict = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSString *nssLevelsCompleted = [myDict objectForKey:@"LevelsCompleted"];
LevelsCompleted = [nssLevelsCompleted intValue];
LevelsCompleted = 445;
[myDict setObject:nssLevelsCompleted forKey:@"LevelsCompleted"];
[NSKeyedArchiver archiveRootObject:myDict toFile:path];
看一看此http://計算器。 com/questions/8732405/is-there-a-video-for-writing-to-plist-in-ios – Sbhklr 2012-01-27 23:45:26
thx ill看看 – mattblessed 2012-01-27 23:47:34
我的代碼一直在返回(null) – mattblessed 2012-01-28 02:18:10