Thanks @slembcke! Now it is working perfectly :)
One thing that I have noticed that NSData or NSValue is taking more disk space then using NSArray with NSStringFromCGPoint. Can I somehow make the size smaller since my replay data file has already 2,2MB and I have stored only 6 replays.
Chipmunk physics + replay system
(37 posts) (8 voices)-
Posted 6 months ago #
-
I wouldn't use plists at all. If you pack all of the data into a single NSData object it will be a fraction of the size of a plist, even a binary plist.
Posted 6 months ago # -
Thanks again @slembcke!
I followed your advise and I am completely storing all my replay data in an single NSData object. Works much better then the NSCoding method and the file size is much smaller then previous :) But I have noticed that almost the same replay file on my iPad2 is 3 times bigger then on my iPhone 3GS. Why is it like this?
And another question. Do I have to free the const void *data on dealloc? Since when I try to put this line into dealloc:
free(data) ;Then I get a crash each time when I want to restart the scene and playback the replay again.
Posted 6 months ago # -
No the buffer that pointer points to is owned by the NSData and will be freed along with it. You don't need to (and shouldn't !!) free it.
Not sure why the filesize would be larger on the iPad 2. It's not going to be using different data types, so you must be saving more of them for some reason. You would need to print out some info along with your replay to figure that one out.
Posted 6 months ago # -
Hi everybody:
I´m trying to save the position of a box2d body in a NSMutable Array, and after that saving also the NSMutableArray with no success, this is the code that I use:
//In tick method Position = body->GetPosition();//Get the position of the body; CGPoint Coord = CGPointMake(Position.x, Position.y); //Make a point from the position of the body. NSValue * Puntos = [NSValue valueWithCGPoint:Coord]; //Convert the point into object. NSMutableArray * Coords = [[NSMutableArray alloc] initWithObjects:Puntos, nil];//Create and initializate the array [Coords addObject:Puntos];//Add objects to the array. //Set the path were the array will be saved NSArray * caminos = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * directorio = [caminos objectAtIndex:0]; NSString * coordenada = [ directorio stringByAppendingPathComponent: @"coordenadas"]; //saving the array. [Coords writeToFile:coordenada atomically:YES];But no file is saved when I simulate it...I´m a nob, and I´m trying to figurate out why, if I´m adding objects to the array, I don´t get the file....Please, could you gave me a trace what I´m doing wrong??
Thanks.
PD: I know chipmunck is not box2d, but the issue is very similar to what has been posted here.Update: If I change the way to save the file and use NSKeyedArchiver like this:
[NSKeyedArchiver archiveRootObject:Coords toFile:coordenada];
Then I got a file, but it is save just on NSPoint, the last where the object remain....
So, could you give me a trace of why I only save the last point?
Thanks.Posted 1 month ago # -
You should really start a new thread, but here's the reason:
http://stackoverflow.com/questions/751093/problem-writing-a-nsmutablearray-to-file-in-cocoaPosted 1 month ago #
Reply
You must log in to post.