0

Now I am working on an app based on SKScene. And I want to store some SKShapeNode to system defaults so user can still see them when reopening the app after it is totally closed. I store the SKShapeNodes in a NSMutableDictionary. I tried to store it to NSUserDefault using setObjectForKey but it gave me the error:

Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType').

Because I am trying to add SKShapeNode to it. So how can I store it like the way of NSUserDefault? Thanks so much!!

Here is my code: myNode = [SKShapeNode shapeNodeWithCircleOfRadius:radius]; [myNode setPhysicsBody:[SKPhysicsBody bodyWithCircleOfRadius:radius]]; myNode.fillColor = [uicolor greenColor]; myNode.lineWidth = 1.0; [myNode setPosition:positionInScene1]; myNode.antialiased = YES; myNode.glowWidth = 0.0; myNode.physicsBody.allowsRotation = NO; myNode.physicsBody.dynamic = YES; myNode.physicsBody.restitution = 0.3; [mainLists myNode forKey:someKey];(mainList is a nsdictionary) NSUserDefault *store = [NSUserDefault standardDefault]; [store setObject:mainList forKey:@"mainList"]; [store sychronize];

zh_Vincent
  • 17
  • 4

1 Answers1

0

You can try

[NSKeyedArchiver -archivedDataWithRootObject:]

first you serializable object to the NSData, then save data to the userDefault.

When you want to read the data, you should decode the data to the SKShapeNode using NSKeyedUnarchiver

You can learn from NSKeyedArchiver/NSKeyedUnarchiver Or you can only save the property of the node

Suen
  • 1,110
  • 1
  • 7
  • 13
  • Can you explain more in specific way? I haven't used that before. If I create one like SKShapeNode *node = [SKShapeNode shapeNodeWithCircleOfRadius:radius]; and I set many properties of it like mass, physicsBody, lineWith, color. So how can I store it and load it using the way you provided? – zh_Vincent Jan 12 '15 at 05:22
  • I have figured out! Thanks a lot! – zh_Vincent Jan 12 '15 at 11:10