#techpost #SDL3 #CThis sprite image stuff is SOOO FIDDLY!
I mean it makes sense, and I think it's a great idea, but so fiddly.
I should put the code on codeberg, I'm write a C struct sprite that abstracts
an arbitrary multi-sprite sprite file. The only constraint is that the image must
be cut into squares of equal size.
(Which it seems is how sprites files work, except I bet I will find ones
where the individual sprites are not all the same dimension.)
SO like I instantiate a sprite with an image file. (and the relevant SDL3 renderer
texture and surfaces needed, but that's more bookeeping just to draw them to
the screen)
/* the important params are the image file, and the image dimensions, and dimension of each sprite */
struct sprite_sprite * sprite1 = NULL;
sprite1 = sprite_make_sprite([...sdl-stuff...], "media/image-file.png", 700, 400, 16, 16);
Then I can draw it with:
/* 3, 7 is row and column */
sprite_render(sprite1, 3, 7);
So the virtual row and column gets turned into the actual coordinates to
sub-index into in the sprite file.
Currently I have one good sprite file that has walls, players, monsters, ... etc. in it.
So my program will just have one instance of struct sprite_sprite * like above.
This seems like a decent trade-off (so far) between convienience and over-engineering.
I like how C makes this stuff harder, but in a good way. Because it feels good to struggle
through this stuff and think about it.
Like I am imagining that the better designs that it forces on me would also be better
in a higher level language. For example, lots of times I worked with python devs that knew the cost of
nothing. [0]
[0] yeah that's the lisp saying applied to python.