Alternatives to NSMutableArray for storing 2D grid - iOS Cocos2d

Posted by SundayMonday on Game Development See other posts from Game Development or by SundayMonday
Published on 2012-12-02T22:36:04Z Indexed on 2012/12/02 23:27 UTC
Read the original article Hit count: 315

Filed under:
|
|

I'm creating a grid-based iOS game using Cocos2d. Currently the grid is stored in an NSMutableArray that contains other NSMutableArrays (the latter are rows in the grid). This works ok and performance so far is pretty good. However the syntax feels bulky and the indexing isn't very elegant (using CGPoints, would prefer integer indices). I'm looking for an alternative.

What are some alternatives data structures for 2D arrays in this situation?

In my game it's very common to add and remove rows from the bottom of the grid. So the grid might start off 10x10, grow to 17x10, shrink to 8x10 and then finally end with 2x10. Note the column count is constant.

I've consider using a vector<vector<Object*>>. Also I'm vaguely aware of some type of "fast array" or similar offered by Cocos2d. I'd just like to learn about best practices from other developers!

© Game Development or respective owner

Related posts about cocos2d-iphone

Related posts about ios