I spent the whole afternoon yesterday trying to figure out how to do sprite collisions like this, never thought of using a mask in this way, thanks for sharing the knowledge!
I love How conside and short your codes are. Handmade hero also does a great job and he goes into every detail on windows programming but its little overwelming and in your case its easier and encouraging so thanks
Thanks mate 😁 I'm glad I was able to bring your done joy; I had plenty of good times back then 😊 I put up a channel with as many of my old streams as I could for people from back then who want to revisit it. It's not monetized or anything 😉 www.youtube.com/@UltimaN3rdsStreamArchive/videos
It's a long time coming, but it will come :) I went through several iterations of code before arriving at the current one, and I've been developing my game further so as to put that collision code through more testing before putting it out there. The collision response video will be within my next few videos now 👍
Great video. I've been trying to adapt this to get it to work with raylib, but have been unsuccessful so far. CollisionMaskFromSprite -> incompatible pointer type error. Which makes sense, as the raylib Texture2D type is different from the mask type. Still have to figure it out... :)
@@UltimaN3rd I am curious though, in code for your actual projects do you store the mask's boolean values individually? For the sake of the tutorial it makes the concept much clearer, but in practice spending 8 bytes per bool when each one really only needs 1 byte.
Truetype fonts are quite a bit more complex so initially I'll be showing how to use simple bitmap fonts, but I'm sure I'll get to Truetype as well. Cheers.
Isnt that demanding too many resources? I mean first calculating if two shapes overlap and then calculate which of the color pixels of each shape are beyond that point etc imagine having 40 such shapes colliding with each other and needing to have all that calculated in a single frame per frame
Generally in a game you won't actually have that many objects overlapping, so the key to optimization is to use faster techniques to only check objects pixel-by-pixel when you know they're overlapping. Let's say you have 40 objects on-screen, probably most of them are only in the vicinity of 5 others, and ultimately only about 10 of them have any actual overlap with 1-3 other objects. Therefore you only need to do per-pixel checking for a few small overlapping areas a few of your objects. In low-resolution games such as many indie games, you could easily perform these types of collision checks for everything you need in each update cycle in a few hundred microseconds.
lol if you wrote done something like 40k or 400k, then sure, but 40? That's something probably my calculator's cpu could churn out couple of times a second
Worst case scenario, if it really was for some reason causing performance issue, you could always fallback on ol' reliable and generate a quad tree to speed up the pixel to pixel checks
Also using a bool array is just wasteful, you can speed this up by packing data into bit masks. Once you have that you can use simd, if the compiler couldn't figure out how to vectorize your algorithm automatically. Depending on the available instruction set, you will be able to check 128, 256 or 512 pixels in a single (or few) CPU cycle(s).