I'm trying to create a game in Cocos2D-X with a tile map and I'm getting the below error:
EXC_BAD_ACCESS (code=2, address=0x0) in the line setContentSize(CCSizeZero); of the method CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
I'm creating the tile map in this way:
this->background = tileMap->layerNamed("Background");
Somebody knows what it's happening?
Please, could you help me?
Ok, I've found the problem. Just a little of theory:
EXC_BAD_ACCESS code=2 means that the pointer is corrupt and this could happen because:
So, in my case, I thought that
initWithTMXFile was good enough to initialize the
tileMap pointer but I was wrong. The solution is that first thing before
tileMap must be initialized. So, the correct block of code is:
this->tileMap = new CCTMXTiledMap(); this->tileMap->initWithTMXFile("TileMap.tmx"); this->background = tileMap->layerNamed("Background"); this->addChild(tileMap);
I hope it helps.