Recommended way to draw animations? #35
-
For the so_long project I have to draw a grid of sprites, and I'm wondering whether with MLX42 it's better to make every tile on the grid its own image, or to only have one of every image and to make a new instance of an image for every tile. Only keeping one of every image seems most logical to me since it should be faster:
But on the other hand, there doesn't seem to be a function for deleting instances.
Which of these points is recommended, why, and do I have any (or a lot of) misconceptions? It feels like what the library is missing is a way to turn off specific instances, like how |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Truly the best way to draw many sprites in a grid like fashion is to make an image per sprite texture, then The short reason why there isn't a The long answer is because it's a lot of memory management in order to actually do that. To address this I might need to make some API breaking changes to fix this properly. Take for example the instances array; You access each instance via an index but if you delete instance 2 out of 3 instances you now have a hole in the middle of the array and if you move the other instances their indexes are all messed up now. Now the solution would be to simply use a linked list but then we already break the API (with which i'm fine btw) it might just make others unhappy. Additionally you can then no longer access each index via the This really just leaves me with a boolean variable that toggles the rendering of the instance itself, this doesn't really 'delete' the instance just skips it OR rewrite it all to use a linked list and make a major update. If you have any ideas what to use as an alternative, feel free to share 👍 |
Beta Was this translation helpful? Give feedback.
Truly the best way to draw many sprites in a grid like fashion is to make an image per sprite texture, then
mlx_image_to_window
the sprite you want to draw for your grid of sprites. You already have the texture in memory no need to create a new image for each sprite texture.The short reason why there isn't a
mlx_delete_instance
function is because I haven't really implemented it yet, most of the time it's enough to just move the instance into the background or out of the sight of the player, sure a bit wasteful, but its even a common practice in the gaming industry itself and your GPU is not going to die drawing a little quad.The long answer is because it's a lot of memory management in…