Dynamically build a background for BPLAN from tiles at runtime
Moderator: Stef
Dynamically build a background for BPLAN from tiles at runtime
Hi,
I have 8 different 8x8 tiles that I'd like to random load and position in BPLAN. All tiles share the same palette but I'm not sure how to assemble them into a Image at runtime. Does anyone have an advice on this? It will be warmly welcome as always
I have 8 different 8x8 tiles that I'd like to random load and position in BPLAN. All tiles share the same palette but I'm not sure how to assemble them into a Image at runtime. Does anyone have an advice on this? It will be warmly welcome as always
Re: Dynamically build a background for BPLAN from tiles at runtime
Maybe you could use a 2d array for this along with a random number generator where each number is a certain tile.
The random numbers could be put into the 2d array and the array would then build up an image.
The random numbers could be put into the 2d array and the array would then build up an image.
Re: Dynamically build a background for BPLAN from tiles at runtime
I've already got that far The issue I'm having is how do you create the image? I understand I can possibly use a tile-set via rescomp but I wouldn't know where to begin after thatHik wrote:Maybe you could use a 2d array for this along with a random number generator where each number is a certain tile.
The random numbers could be put into the 2d array and the array would then build up an image.
Re: Dynamically build a background for BPLAN from tiles at runtime
If it has to be on the BPLAN then the best way I know of how to do it so far is to individually load each tile as an image.
I'm thinking you can just load that one palette and have all the tile images use that same one.
I'm thinking you can just load that one palette and have all the tile images use that same one.
Re: Dynamically build a background for BPLAN from tiles at runtime
That won't work as the PAL data will be different for each image you load in using ResComp I think I need to load a tileset and then indicate where I want each tile vdp_tile.h has the functions I'm just not sure on the combo I needHik wrote:If it has to be on the BPLAN then the best way I know of how to do it so far is to individually load each tile as an image.
I'm thinking you can just load that one palette and have all the tile images use that same one.
Re: Dynamically build a background for BPLAN from tiles at runtime
The code worked for me when using sprites. I'm thinking images work the same.matteus wrote:That won't work as the PAL data will be different for each image you load in using ResComp I think I need to load a tileset and then indicate where I want each tile vdp_tile.h has the functions I'm just not sure on the combo I needHik wrote:If it has to be on the BPLAN then the best way I know of how to do it so far is to individually load each tile as an image.
I'm thinking you can just load that one palette and have all the tile images use that same one.
Just make sure if you put the palette into palette 0 (with memcpy(&palette[0]... and VDP_setPalette(0 ... ) that you put PAL0
into the code for each image you load (right after TILE_ATTR_FULL).
Code: Select all
// load background
ind = TILE_USERINDEX;
VDP_drawImageEx(BPLAN, &placeholder1_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 8, 8, FALSE, TRUE);
ind += placeholder1_image.tileset->numTile;
VDP_drawImageEx(BPLAN, &placeholder2_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 8, 8, FALSE, TRUE);
ind += placeholder2_image.tileset->numTile;
memcpy(&palette[0], placeholder1_image.palette->data, 16 * 2);
VDP_setPalette(0, placeholder1_image.palette->data);
Re: Dynamically build a background for BPLAN from tiles at runtime
Mmm I'll have a go with this tomorrow see what happens I'm not sure if the method you're suggest wastes VRAM as essentially every call you're making there is allocating Vram to each tile you load. While what needs to happen in my case is I load 8 tiles at 8x8 and reference them at specific points.Hik wrote:The code worked for me when using sprites. I'm thinking images work the same.matteus wrote:That won't work as the PAL data will be different for each image you load in using ResComp I think I need to load a tileset and then indicate where I want each tile vdp_tile.h has the functions I'm just not sure on the combo I needHik wrote:If it has to be on the BPLAN then the best way I know of how to do it so far is to individually load each tile as an image.
I'm thinking you can just load that one palette and have all the tile images use that same one.
Just make sure if you put the palette into palette 0 (with memcpy(&palette[0]... and VDP_setPalette(0 ... ) that you put PAL0
into the code for each image you load (right after TILE_ATTR_FULL).
Code: Select all
// load background ind = TILE_USERINDEX; VDP_drawImageEx(BPLAN, &placeholder1_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 8, 8, FALSE, TRUE); ind += placeholder1_image.tileset->numTile; VDP_drawImageEx(BPLAN, &placeholder2_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 8, 8, FALSE, TRUE); ind += placeholder2_image.tileset->numTile; memcpy(&palette[0], placeholder1_image.palette->data, 16 * 2); VDP_setPalette(0, placeholder1_image.palette->data);
Re: Dynamically build a background for BPLAN from tiles at runtime
I expected the following code to simply load the tiles into VRAM at the next free position:
But what I end up with is this!
Code: Select all
ind = IndMarker;
VDP_setPalette(PAL2, map_tileset.palette->data);
VDP_loadTileSet(map_tileset.tileset, ind, 1);
Re: Dynamically build a background for BPLAN from tiles at runtime
Fixed it!!! Wasn't updating IndMarker and for some reason it was just completely filling the rest of VRAM with the same tile?!?