現在我已經在應用商店中創建了我的遊戲「激光防禦者」及其應用商店,但我有一件事我無法弄清楚,如何存儲高分在遊戲列表中。我有一個標籤,可以計算被摧毀的敵方船隻的數量,但是如何將這些分數的最好值存儲在列表中?這是我的代碼更新enemiesShot標籤:如何在Cocos2d的清單中存儲高分
(無效)更新:(ccTime)DT {
的NSMutableArray * projectilesToDelete = [[NSMutableArray裏的alloc] INIT]; 爲(在_projectiles CCSprite *射彈){ 的CGRect projectileRect = CGRectMake( projectile.position.x - (projectile.contentSize.width/2), projectile.position.y - (projectile.contentSize.height/2), projectile.contentSize.width, projectile.contentSize.height);
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init]; for (CCSprite *target in _targets) { CGRect targetRect = CGRectMake( target.position.x - (target.contentSize.width/2), target.position.y - (target.contentSize.height/2), target.contentSize.width, target.contentSize.height); if (CGRectIntersectsRect(projectileRect, targetRect)) { [targetsToDelete addObject:target]; } } for (CCSprite *target in targetsToDelete) { [_targets removeObject:target]; [self removeChild:target cleanup:YES]; _enemiesShot++; [_enemiesShotLabel setString:[NSString stringWithFormat:@"%d",_enemiesShot]]; } if (targetsToDelete.count > 0) { [projectilesToDelete addObject:projectile]; } [targetsToDelete release];
}
爲(在projectilesToDelete CCSprite *射彈){ [_projectiles的removeObject:彈丸]; [self removeChild:拋射清理:YES]; } [projectilesToDelete release];
}
作者:「list」你的意思是「NSUSerDefaults」,或者你只在應用程序運行時才需要? – Suny 2013-03-27 17:24:04
我想將所有最高分存儲在列表中,無論該應用程序是否正在運行。 – 2013-03-27 20:05:26