Here is what I came up with, though obviously this will only work with games that don't use a lot of tiles, because every non-animated tile will need to be duplicated as many times as you have frames in your background animations, but it will let you animate up to 840 tiles in video mode 3 essentially for "free" (trading flash space for cycles).
Say your tileset looks like this:
Code: Select all
A1, A2, A3, S1, S2, S3, S4, S5, S6
My thought was to split that tileset up into 3 tilesets which duplicate all of the static tiles:
Code: Select all
tileset1 = { A1, S1, S2, S3, S4, S5, S6 }
tileset2 = { A2, S1, S2, S3, S4, S5, S6 }
tileset3 = { A3, S1, S2, S3, S4, S5, S6 }
Code: Select all
SetTileTable()
As a quick and dirty proof of concept, since I have 15 different treasure types (in reality they are all the same treasure, but overlaid on 15 different background tiles) that each have 3 frames of animation, and all of those tiles are next to each other in my tileset, I commented out my treasure animating code, and dropped the following chunk of code into my main loop.
Code: Select all
#define TREASURE_FRAME_SKIP 16
#define UNIQUE_TREASURE_TILES_IN_ANIMATION 3
for (;;) { // main loop
WaitVsync(1);
static uint8_t tileCounter = 0;
static uint8_t treasureFrameCounter = 0;
if ((treasureFrameCounter % TREASURE_FRAME_SKIP) == 0) {
SetTileTable(tileset + 64 * tileCounter++);
if (tileCounter > UNIQUE_TREASURE_TILES_IN_ANIMATION)
tileCounter = 0;
}
if (++treasureFrameCounter == TREASURE_FRAME_SKIP * UNIQUE_TREASURE_TILES_IN_ANIMATION)
treasureFrameCounter = 0;
// rest of main loop code...
}
All of the collision testing and other code works without any modifications, because the absolute tile numbers are still the same, the only downside that I can see is that you have to duplicate all of your non-animated tiles, but I currently only have 24 non-animated tiles versus 15 x 3-frame animated tiles. So I would end up duplicating those 24 tiles 3 times for a total tile count of (15 + 24) * 3 tiles used, which is only 117 total, which still leaves me with plenty of room to expand.
The only problem I forsee is gconvert removing the duplicates, so I'd probably have to make each one into a separate tileset, and switch among the tilesets, rather than using offsets within a single tileset, which should actually leave me with even more free tile indicies than before, since at any given point in time, the window of 256 tiles in the tileset only includes 1 frame of every animation, rather than all of them.
Thoughts? Is this really a win-win: no wasted cycles animating background tiles; freeing up extra tile indices because each new tileset only contains a single animation frame of every animated tile, with the only downside being extra flash space consumed because you are now storing multiple tilesets that contain duplicates?