Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Pages: 1
Hi,
I'm sure this has to do with my underdeveloped programming skills in C rather than GBDK, but this problem has driven me crazy since yesterday, and I'm unable to figure it out. I defined a struct type and declared a struct to store where the four 8x8 sprites of a 16x16 sprite are located, like so:
struct sprite16x16
{
UBYTE spriteid_0;
UBYTE spriteid_1;
UBYTE spriteid_2;
UBYTE spriteid_3;
};
struct sprite16x16 sprite2;
If I initialize each member of the struct directly (ie. sprite2.spriteid_0=2, etc.) it works without issue. However, I want to use one function to initialize every sprite16x16 object, so I pass the address of a given sprite and the values of each memeber like this: setup(&sprite2, 2, 3, 4, 5); and then inside the function I initialize each member like this: generic_sprite->spriteid_0=2, etc. But this doesn't work: the members of the struct are initialized with whatever...
I wrote to simple programs isolating the problem. The first one uses the direct method (sprite2.spriteid_0=2) and works, the second one uses the indirect method (sprite2->spriteid_0=2) and doesn't work. Both compile, but the second one shows garbage instead of the sprite. The two programs create an 8x8 sprite (sprite1), and a 16x16 sprite using the methods above.
Program 1: https://justpaste.it/9da2q
Program 2: https://justpaste.it/2yi8v
As I said, I'm sure this is something stupid related to the C language. Hopefully someone can help me out. Thanks!
Edit: Never mind. I was using an obsolete version of GBDK. With the latest version, the code does what I want it to do...
Last edited by popcalent (2021-08-23 12:57:24)
Offline
You might also look into the GBDK-2020 metasprite features:
https://gbdk-2020.github.io/gbdk-2020/d … f9d1cf392b
Offline
bbbbbr wrote:
You might also look into the GBDK-2020 metasprite features:
https://gbdk-2020.github.io/gbdk-2020/d … f9d1cf392b
Thanks! That IS useful.
Offline
Pages: 1