3
\$\begingroup\$

i am working on a tile roguelike i got some of the basics working using this tutorial http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

but i want to be able to create a map programatically instead of using the tiled editor

just add a NSArray of sprites/tiles to my CCLayer derived class or something, or should i make use of the CCTMXTiledMap class?

can anyone gimme some hints about how to do this? or know of a tutorial or sample code somewhere?

thanks a lot

\$\endgroup\$
  • 1
    \$\begingroup\$ I suggest looking into the CCTMXTileMap and CCTMXLayer class and see how they operate. Perhaps that will help you figure out if this is feasible. \$\endgroup\$ – Moshe Jul 17 '11 at 12:59
4
\$\begingroup\$

You only need a CCTMXLayer, there is no need for any thing else. but you'll need to initialize it properly. for that reason I suggest you use some TMX file generated with Tiled editor and then load it into your program. there is a GID value for each tile in TMXLayer and you can easily edit it. by changing that value the tile for that position will change. if you set a tile's GID to 0 TMXLayer will automatically delete tile at that position otherwise, it'll change(or create) the ccSprite instance at that position.

\$\endgroup\$
  • \$\begingroup\$ This is a clever solution. It didn't occur to me just to load a "blank" map and then modify it to make it random. \$\endgroup\$ – Clay Aug 28 '12 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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