I'm mainly a python developer, so pls don't be too cruel to me ;-;

I'm making a port of a game to the TI 84 CE using the CE C toolchain, however I have run into the issue of compressing and decompressing sprites. I know how to do it, but is there a way to use a for() loop to decompress several at a time? I don't want spaghetti code, nor do I want my code to look like


Code:
gfx_sprite_t *image;
image = gfx_MallocSprite(image_width, image_height);
zx0_Decompress(image, image_compressed);

gfx_sprite_t *imageTWO
imageTWO = gfx_MallocSprite(imageTWO_width, imageTWO_height);
zx0_Decompress(imageTWO, imageTWO_compressed);

etcetera


Any help is appreciated! Again, I apologize if the answer is an obvious one I'm not the best at this
I should mention that I also used the compressed sprite example as a guide, I just added multiple images to convimg.yaml instead of just one. Idk if this is necessary info but I figured it may be good to know
I would suggest looking at the tilemap_compressed example, particularly these lines. The example decompresses sprites generated from convimg to an array of sprite pointers. It goes on to use them in a tilemap, but you can index the array to get the sprites you need. If the sprites are different dimensions, you would also need some way to iterate through these such as an array for each width and an array for each height.

My example would be:

Code:
gfx_sprite_t *sprites[NUM_SPRITES];
uint8_t sprite_widths[] = {8, 10, 12,15,...};
uint8_t sprite_heights[] = {15, 12, 17, 33,...};

for (i = 0; i < NUM_SPRITES; ++i)
{
    tmp_ptr = gfx_MallocSprite(sprite_widths[i], sprite_heights[i]);
    zx7_Decompress(tmp_ptr, sprites_compressed[i]); // This comes from your convimg
    sprites[i] = tmp_ptr;
}

gfx_Begin();

// You can now draw your sprites however

gfx_Sprite(sprites[INDEX_TO_DRAW], DRAW_X, DRAW_Y);



I can't test that right now but I believe it all should work.
You don't need to store the width/height if you use gfx_GetZX7SpriteSize. Also the sprite array should be const.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement