Pergunta

I'm working on an iOS game and I'm using the NSCoding protocol to save my levels in my editor and to load them in game. I was wondering if it was possible to somehow reuse an NSKeyedUnarchiver after it's been used to load the level. For instance when the player wan't to restart the level. I can't simply create and load a new instance of the level, because I want to keep the same objects, just reset their properties.

Foi útil?

Solução

You can re-use the data, which is passed down to decoder. You cannot "reset" the existing objects to initial state, though.

While you can do this on your own, I'd suggest to just invalidate the whole tree of objects and re-load them from possibly cached data.

That surely depends on the number of objects, but if you have enough of them for the process to be visibly slow, I believe you have lots of other more important optimisations to do.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top