Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-19-2010, 08:07 PM   #1 (permalink)
ama269
Registered Member
 
ama269's Avatar
 
Join Date: Jul 2009
Location: Austin, TX
Posts: 482
ama269 is on a distinguished road
Default Added High Score Feature w/Data... now stuck

This might take a little time to explain, but please help...

I am using cocos2d, and OS 4.0.

I recently implemented a high-score feature - pretty basic (note none of these issues occur prior to implementing and works fine on OS 3.2 but the application has to load again, hence the point of multi-tasking and OS 4.0):

- When I open the game scene, the high score is loaded from a file.

- Then, once the player loses the high score is checked with the current score.

- If it's higher, write to the file then go to the game over scene which displays the current score and an up-to-date high score.

- There are some buttons in the game over scene - play again, other apps, main menu, etc. and when the user is working in the app moving back and forth from different layers and scenes, everything works fine.

When I exit the app I need to do so by holding down the icon in the bottom bar, then hitting the minus sign.

The issue at hand is that when I close the app from the bottom bar (I see SIGKILL in the bottom of xCode) and go to re-open the app, it just shows a frozen screen of where the app last was.

I then need to re-build/launch from xCode for the application to work properly again.

It seems like the solution is:
- Put in code to write to the file when the application is killed (when I see SIGKILL on xCode), when I'm pressing the minus sign as it's running in the background (similar to applicationWillTerminate in the pre 4.0 days when the home-button is pressed)

Any idea how I detect this "SIGKILL"?




Here is some of the code I'm using to write to the array file:

dataFilePath method:

- (NSString *)dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kFilename];
}

Pulling info from the file code:

NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
globalTopScoreString = [array objectAtIndex:0];

globalTopScore = [globalTopScoreString integerValue];

[array release];
}
else
{
globalTopScore = 0;
}

Writing to the file:

NSMutableArray *array = [[NSMutableArray alloc] init];
globalTopScoreString = [NSString stringWithFormat:@"%i", globalTopScore];
[array addObject:globalTopScoreString];
[array writeToFile:[self dataFilePath] atomically:YES];
[array release];

Last edited by ama269; 06-19-2010 at 08:09 PM.
ama269 is offline   Reply With Quote
 

» Advertisements
» Online Users: 417
20 members and 397 guests
Absentia, apatsufas, Apptronics RBC, brainspoon, comicool, Creativ, Davor, Domele, iMax 3060, jbro, JoeRCruso, JohnnyFlash, linkmx, matador1978, mistergreen2011, Newbie123, NSString, revg, RickSDK
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,551
Threads: 94,078
Posts: 402,725
Top Poster: BrianSlick (7,990)
Welcome to our newest member, hongto24
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.