为多个级别的iOS游戏工作。我一直在玩,这就是我想出来的:
保存级别:
-(void)gameEnded {
_touched = YES;
if (_touched == YES) {
beatLevel = YES;
NSLog(@"touched");
[self runAction:[SKAction sequence:@[
[SKAction runBlock:^{
level2Achieved = [[NSUserDefaults standardUserDefaults] integerForKey:@"newLevelAchieved"];
if (beatLevel == YES) {
level2Achieved = 2;
}
[[NSUserDefaults standardUserDefaults] setInteger:level2Achieved forKey:@"newLevelAchieved"];
[[NSUserDefaults standardUserDefaults] synchronize];
}],
[SKAction waitForDuration:0.5],
[SKAction runBlock:^{
MyScene *mainMenu = [[MyScene alloc] initWithSize:self.size];
[self.view presentScene:mainMenu transition:[SKTransition fadeWithDuration:0.6]];
}],
]]];
}
}
然后我将水平头文件导入我的主菜单(选择级别1-40),并设置以下代码以查看是否选择了下一级别:
//set up levelAchieved:
level2Achieved = [[NSUserDefaults standardUserDefaults] integerForKey:@"newLevelAchieved"];
当用户点击关卡以查看是否已解锁时,再加上if语句:
if ([node.name isEqualToString:@"lv2"] && level2Achieved == 2) {
testScene2 *firstLevel = [[testScene2 alloc] initWithSize:self.size];
[self.view presentScene:firstLevel transition:[SKTransition fadeWithColor:[SKColor whiteColor] duration:0.5]];
}
这对我有用,但在接下来的38个级别之前,这是正确的方法吗?我是否写过
//set up levelAchieved:
levelXAchieved = [[NSUserDefaults standardUserDefaults] integerForKey:@"newLevelAchieved"];
每个新关卡? 有没有办法用NSMutableArray做到这一点?或者是一种覆盖NSUserDefaults的方法,如果没有程序忘记上一级被解锁了吗?
答案 0 :(得分:0)
尝试制作NSMutableArray
并在每次玩家达到新等级时为其添加值。即NSString然后在玩家点击该等级之前检查NSString是否等于某个值?