Domanda

I have a subclass of SKShapenode with 2 extra attributes

@property(assign)float size;
@property(assign)float weight;

But when I save a NSMutableArray, with core data, containing some subclasses of my node, the information about size + weight is lost.

newLevel.tractorObjects = [NSKeyedArchiver archivedDataWithRootObject:arrayTractorObjects];

How can I solve this problem?

È stato utile?

Soluzione

Since you appear to be using NSCoding to encode the nodes, you need to implement NSCoding in your subclass. Right now SKShapeNode is doing all of the encoding, but it doesn't know about your subclass attributes. To get your attributes encoded, you need to implement encodeWithCoder and initWithCoder. Both of these should call super's implementation so that SKShapeNode can encode itself, and then add/extract your own attributes.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top