Im creating a tilemap which have about 10.000 tiles. So am i use interger array to set its texture and properties or is there another way ?
From a storage perspective, an array of 10 000 isn’t all that bad, especially since they’re integers. That’s only ~40kb of memory assuming you’re using 32-bit unsigned integers… definitely not worth worrying about.
If you’re worried about drawing, it depends on your context I guess. Like, if your screen only shows a small portion of that tilemap at any given time then just take steps to only render that. If you need to render the whole thing, then it’s probably still fine but if you’re finding you have performance issues you can look at optimizations.
Simple 1D-array will do the job.
class Tile {
public int X { get; set; }
public int Y { get; set; }
public Texture2D Texture { get; set; }
}
class Core {
public Core( ) {
Tile[] tiles = new Tile[10000];
}
}
Just a heads up here, you don’t necessarily need to associate a Texture2D with an individual tile. Instead, you can associate your Tiles array with a Texture2D in, say, a TileMap class.
It’s a reference, so it’s not a big deal, but it does unnecessarily inflate the size of your Tile object.