Accessing the data from a tileset

SGDK only sub forum

Moderator: Stef

Post Reply
darkjoy2k2
Interested
Posts: 15
Joined: Tue Nov 13, 2018 8:42 pm
Location: Germany
Contact:

Accessing the data from a tileset

Post by darkjoy2k2 » Sun Nov 25, 2018 9:24 am

i have set up a tile-scrolling effect to create some water effects like in Neutopia 2 and i didnt wanted to use scrolling or sprites for that.

So i set up 2 Images:

Code: Select all

const u32 movtile[2][8] =
{{
		0x81111111,
		0x18111111,
		0x11811111,
		0x81181111,
		0x81118118,
		0x11111811,
		0x11111181,
		0x11111118
},

{
		0x11111118,
		0x11111181,
		0x11111811,
		0x81118111,
		0x81181118,
		0x11811111,
		0x18111111,
		0x81111111
}};

...

for (x = 0; x<8;x++)
{
    movtile_A[x] = movtile[0][x];
    movtile_B[x] = movtile[1][x];
    // movtile_C[] is just a cache
}
And do some circular bitshift to the Variables:

Code: Select all

            
        for (x = 0; x<8;x++)
            {
                movtile_C[x] = movtile_A[x];
                movtile_A[x] = movtile_A[x] << 4 | movtile_B[x] >> 28;
                movtile_B[x] = movtile_B[x] << 4 | movtile_C[x] >> 28;
            }
            VDP_loadTileData( (const u32 *)movtile_A, 3, 1, 0);
            VDP_loadTileData( (const u32 *)movtile_B, 4, 1, 0);
            VDP_loadTileData( (const u32 *)movtile_B, 43, 1, 0);
            VDP_loadTileData( (const u32 *)movtile_A, 44, 1, 0);
Works well and does a nice left shift over every tile have been placed on that number,

Only problem now is instead of defining every tile i like to shift by hand in a field of arrays i´d like to access the tileset i imported with rescomp.

Code: Select all

// gfx.res
TILESET tiles_image "gfx/tiles.png" 0

// main.c
VDP_loadTileSet( &tiles_image, TILE1, 0); //ts_1 is a tileset
tried something like

Code: Select all

for (x = 0; x<8;x++)
{
    movtile_A[x] = tiles_image.tiles[1][x];
    movtile_B[x] = tiles_image.tiles[2][x];
    // movtile_C[] is just a cache
}
Resulting error
src\main.c|243|error: subscripted value is neither array nor pointer nor vector|
“No one in the world gets what they want and that is beautiful.” “You'd be amazed how much research you can get done when you have no life whatsoever.” “I created the OASIS because I never felt at home in the real world."
Ernest Cline

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Accessing the data from a tileset

Post by cero » Sun Nov 25, 2018 6:19 pm

tiles_image.tiles[32/4 * num]

Each tile is 32 bytes. The pointer is 32-bit, so divide by four.

darkjoy2k2
Interested
Posts: 15
Joined: Tue Nov 13, 2018 8:42 pm
Location: Germany
Contact:

Re: Accessing the data from a tileset

Post by darkjoy2k2 » Sun Nov 25, 2018 9:15 pm

Thanks! I will try that tomorrow.

In the meantime i made myself a Windows-Aplication to turn an indexed image to a set of values that can be directly in the code... Like to share it if someone is interested because i did not find any Programs with this feature.
https://drive.google.com/open?id=1dW3_F ... ZBm7rLi_-7
“No one in the world gets what they want and that is beautiful.” “You'd be amazed how much research you can get done when you have no life whatsoever.” “I created the OASIS because I never felt at home in the real world."
Ernest Cline

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Accessing the data from a tileset

Post by cero » Mon Nov 26, 2018 9:19 am

Save your image as XPM and open it in a text editor ;) Gimp also has direct "export as C".

darkjoy2k2
Interested
Posts: 15
Joined: Tue Nov 13, 2018 8:42 pm
Location: Germany
Contact:

Re: Accessing the data from a tileset

Post by darkjoy2k2 » Mon Nov 26, 2018 9:44 am

Good to know!

i work most with photoshop or Pro Motion NG and
they dont have that feature/module/plugin.

Sometimes DIY works best and gives you most control =)
“No one in the world gets what they want and that is beautiful.” “You'd be amazed how much research you can get done when you have no life whatsoever.” “I created the OASIS because I never felt at home in the real world."
Ernest Cline

darkjoy2k2
Interested
Posts: 15
Joined: Tue Nov 13, 2018 8:42 pm
Location: Germany
Contact:

Re: Accessing the data from a tileset

Post by darkjoy2k2 » Mon Nov 26, 2018 5:30 pm

cero wrote:
Sun Nov 25, 2018 6:19 pm
tiles_image.tiles[32/4 * num]

Each tile is 32 bytes. The pointer is 32-bit, so divide by four.
So it really works! Thx!!!

My code is

Code: Select all

        
for (x = 0;x < 8; x++)
{
    movtile_A[x] = tiles_image.tiles[8 * 80 + x];
}
Can i access the tiles stored with VDP_Loadtiledata() too? Or is it a one way ticket?
“No one in the world gets what they want and that is beautiful.” “You'd be amazed how much research you can get done when you have no life whatsoever.” “I created the OASIS because I never felt at home in the real world."
Ernest Cline

Post Reply