I have defined an array of Tile objects in my header
Tile* tiles;
Then when I try to run functions on the class referred to in the array I get an error code saying EXC_BAD_ACCESS.
Tile* tiles[100][100];
for (int x=0;x<40;x++){
for(int y=0;y<40;y++){
tiles[x][y] = new Tile("tile_grass.png");
tiles[x][y]->setPositionWorld(WorldPos::posWithPosition(x, y)); // error comes when this is ran
this->addChild(tiles[x][y]);
}
}
it seems to work fine if I use a normal pointer instead of an array of pointers, but I somehow have to store that the coordinates x and y hold that specific Tile object. How can I fix this?
I tried the code below and it worked very fine.
`
I reckon the problem is either in your constructor or the function call.