Page 1 of 1

A challenge with tiles..

Posted: Thu Mar 26, 2020 10:17 am
by McValdemar
Let's say that i have an image, which size multiple of 8 where I want to store all my tiles.
For instance 320x320. That imagine contains 1600 tiles. (I know the limit of 1310, this is just for example).

But in the game each bakground element (t1, t2, t3, ...) made up of 5x5 tiles, as I splitted the image.

Image

1) How can I load all at once and then refer to each tile for drawing?

2) Is there a way to have an array used in the resources file so, even if I have different graphics files, I can load in ANIM[1], ANIM[2], etc... ?

Re: A challenge with tiles..

Posted: Fri Mar 27, 2020 11:12 pm
by Miquel
Let’s first agree on what’s the situation: as I understand you have a map, a 2D matrix, where each element is a metatile of 5x5 tiles. Is that correct?
Something like this:

struct Tile
{
int indexOfTileOnVRAM;
int colisionResponseIndex;
};

struct Metatile
{
Tile tiles[ 5 ][ 5 ];
};

const Metatile metatiles[ “whateverNumberYouNeed” ] ={ {},{},… };
int g_map[ 320 ][ 320 ]; // Each element is a index that points to the array of metatiles

First thing that pops to mind is the convenience of always using number belonging to the power of 2.

Is that the precise structure are we talking?