nscoding a ccsprite

Apprentice
Posts: 6
Joined: 2011.05
Post: #1
i have been trying to encode my player class which is a subclass of ccsprite. However it doesn't load properly. the debugger says it exists but not on the screen and my movement doesn't work.
Here is my encoding and decoding code for the player class.
Code:
- (void) encodeWithCoder:(NSCoder *)encoder{
    [encoder encodeCGPoint:self.position forKey:kPositionKey];
    [encoder encodeObject:self.inventory forKey:kInventoryKey];
}

- (id) initWithCoder:(NSCoder *)decoder{
    return [self initWithPosition:[decoder decodeCGPointForKey:kPositionKey]
                        inventory:[decoder decodeObjectForKey:kInventoryKey]];
}
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
For that to work, your entire Cocos2D scene would have to be serialized. Pretty certain that Cocos2D doesn't support that, and probably never will.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2011.05
Post: #3
so then how would i do any sort of save game using cocos2d. because even if i pull the nscoding out and just set those variables in the scene the player still doesn't appaer. the code for that part initalizes the ccsprite then sets its position and inventory.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
You don't need serialization to implement save games. You just need to store the things that are important and use that to make a new scene.

Depending on your needs, your save data could be as simple as the player's location, the number of enemies, and the enemy locations. You don't need to do a full serialization to save and load that.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  nscoding issue shadowgate15 2 3,546 May 24, 2011 08:45 PM
Last Post: shadowgate15