Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

my game features several tilemaps that are initially loaded from a tmx file and modified during gameplay. How can I save the changed tilemaps in a save game? Will NSCoding do the trick here or is the CCTmxTiledMap object too complex for that? How would a sample implementation look for this problem?

share|improve this question

2 Answers 2

TMXGenerator creates and saves a tmx

maybe you could use it, or its code

https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/TMXGenerator

share|improve this answer

NSCoding could end up making your saved games very large.

I am working on a similar problem, not with tiles, but various sprites you can interact with placed around the map. These entities include switches, events, and items. I handle these different ways due to the nature of them.

The items are the easiest to handle. I create a unique id for the item based on the map name, and the position of the item. I can then record this unique id to a list in the permanent game state. I can then check this list on map load to see if the item should be present.

The events are a tiny bit trickier, because I want to be able to easily reference whether an event has occurred in other parts of my game code. So basically this occurs similar to the items, with the exception that I give the event an id of my choosing in the Tiled map editor. This way I can easily say, if event x occurred already, this other thing in my game will be enabled or disabled (without having to look up that event's map and position to figure out a generated unique id for it). This also helps if I decide to move the event's location or something later on.

The trickiest of all is the switches. These are like buttons that can be toggled on or off, so not only do I have to save them in the game state, but I have to save whether they are on or off. For this I can fairly easily use a dictionary to store both the switch's generated unique id (as the key) and the Boolean value as the object stored for that key. This way during map load, I can see if any switches should be different than their default state, and switch them to whatever they should be. Switches can have customized classes associated with them, so switching a switch on could change the state of several tiles on the map, or maybe it only changes an internal value. You can get very complex with this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.