Home > General > Adding tiles to an empty Tilemap

Adding tiles to an empty Tilemap

July 2, 2011

Okay, so I created a nice CCTMXTiledMap for a game.  It’s got two layers: a foreground and a background, each with their own tileset.  I created it in Tiled, and on the background layer, I drew all my happy little trees and water and mountains.  I left the foreground blank.  The plan was to later use setTileGIDat to change tiles in the foreground to little UFOs or aliens or zombies or whatever.

That didn’t work.  I kept getting errors at runtime . (I forget the error, and I’m not about to go back into my code and re-break it to cut and paste one in here.  It was something like “invalid texture”.)

So here’s the hack I used.  I added one tile to the foreground, down in the lower left corner.  (Add it anywhere, I did it at 0,99.  Maybe I’m a lower-class leftist, I don’t know.)  Then in your init, delete that tile with a removeTileAt, and you’ve got a blank layer that will let you set tiles.

Is there some better hack to do this?  You tell me.  I don’t know if there’s a hit on performance or memory during init for doing this, but it works for now, so on to the next fire.

Advertisements
Categories: General Tags: , ,
%d bloggers like this: