0

I have subclassed NSCoding and added my game specific stuff to it such as health etc. I have serialised the object I have subclassed however upon decoding and then adding the sprite to the screen via [self addChild:sprite], it fails to draw the sprite to the screen. I am guessing this is because CCSprite needs to also implement the NSCoding protocol so my questions are:

1) Am I right about my assumption above (I don't want to waste time implementing this solution to only find out this is not the issue) 2) What is the best way to get CCSprite to implement NSCoding? Is it to use Categories or just subclass it and force the subclass to implement the NSCoding protocol?

Hailei
  • 42,163
  • 6
  • 44
  • 69
godzilla
  • 3,005
  • 7
  • 44
  • 60
  • I dint find a connection between your first two statements.. 1 side you are saying you subclassed NSCoding... And added variables to it.. How this class is related to your CCSprite object as sprite must be a CCSprite objects instead of NSCoding object? Right? Correct me if I am wrong... – Nikhil Aneja May 05 '12 at 19:25
  • Sorry it was late at night when i wrote that, i figured out the solution by early morning. The problem i had was i was sending a subclass of CSSprite from one process to another, i was confused as to why the sprite was not being displayed in the receiving process. I figured out not all of the sprite data was being serialised. The solution i implemented was to only send across information i needed such as coordinates,image name etc and just rebuild the sprite from scratch on the receiving end :) – godzilla May 05 '12 at 21:24

1 Answers1

0

LOL sorry it was late at night when i wrote that, i figured out the solution by early morning. The problem i had was i was sending a subclass of CSSprite from one process to another, i was confused as to why the sprite was not being displayed in the receiving process. I figured out not all of the sprite data was being serialised. The solution i implemented was to only send across information i needed such as coordinates,image name etc and just rebuild the sprite from scratch on the receiving end :)

godzilla
  • 3,005
  • 7
  • 44
  • 60
  • The same thing I did when I used NSCoding for my game... Thats why I was surprised to see your question.. As You need to create sprite from scratch.. Just its attributes like position, health etc.that you want come from serialized object.. You can't save CCSprite using NSCoding.. :) – Nikhil Aneja May 06 '12 at 05:13
  • Yup, thank god for the short cut else i would be having a heart attack just about now :) – godzilla May 06 '12 at 23:11