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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-19-2010, 09:07 PM   #1 (permalink)
Registered Member
 
ama269's Avatar
 
Join Date: Jul 2009
Location: Austin, TX
Posts: 482
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 09:09 PM.
ama269 is offline   Reply With Quote
Old 06-20-2010, 03:14 PM   #2 (permalink)
Registered Member
 
ama269's Avatar
 
Join Date: Jul 2009
Location: Austin, TX
Posts: 482
Default

Sorry to bump... but, anyone know?
__________________
Check out our app review & recommendation site: http://www.mobileappbreakfast.com

Site: http://www.mobilebuffaloapps.com

Twitter: http://twitter.com/#!/mobilebuffalo

Facebook: http://tinyurl.com/47ljsf2

Mobile Buffalo's Apps: http://tinyurl.com/2br3ul5
ama269 is offline   Reply With Quote
Old 06-21-2010, 10:26 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 37
Default

Quote:
Originally Posted by ama269 View Post
Sorry to bump... but, anyone know?

Ok, so basically your problem is you are trying to save data to the file system when the app exits, but your applicationWillTerminate is never being called. Correct?

iOS 4 changed a few things when multitasking was introduced. You need to add your file saving code to
Code:
- (void)applicationDidEnterBackground:(UIApplication *)application
You no longer use applicationWillTerminate for this.
__________________
http://www.Vellios.com - iPhone and Macintosh Development Resource
Open source iPhone games and tutorials
NickVellios is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 229
15 members and 214 guests
ADY, AragornSG, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0