i got a question.
is this the hitbox? (all the yellow area)
or the hitbox is the whole square/rectangle
i got a question.
is this the hitbox? (all the yellow area)
VERY good question, @Mega0star01!
I am trying to wrap my head around this myself in this very same moment…
Anyone?
It’s the yellow area, not the whole thing
actually i have no idea, im pretty sure its the whole rectangle though…
Sprite overlaps are computed using the image, so transparent pixels in an image do not count towards overlaps. So the hitbox is in the red outline in that image.
that yellow area is the hitbox. (i think)
The answer is both.
Sprite overlaps are based on the pixels in the image (transparency is ignored). In other words, the yellow area of your example
Tilemap overlaps are based on the outer rectangle of all filled pixels in an image. For your example, that would be the entire outer rectangle of the sprite. For an image like this one:
…it’s the red rectangle (the rectangle around all filled pixels).
Here is an example program that shows the sprite overlap behavior:
The background turns orange when the sprites are overlapping.
And here is another example showing off tilemap behavior:
Note that the sprite you are moving around has a huge transparent chunk in the middle but it still can’t pass through walls and the transparent area still overlaps with tiles
thank you so much, i needed this answer for a fighting game.
Great to know! Just one question… why?? Why not make it pixel perfect for both?
@Sarge good question!
The primary reason is to stop you from getting caught on walls. Imagine you have a character like this:
If they were in a platformer and walked to the edge of a platform, you wouldn’t want them to get caught on their arm or the brim of their hat on the way down. You’d want them to behave like a rectangle.
The second reason is performance. Pixel perfect overlaps are expensive to check; you need to iterate over the pixels of both images to see if there are any two that touch. Meanwhile, rectangle checks are cheap!
You do have a point, after all if I do need pixel perfect collision checks I can just code them myself
(I mean, on a project to project basis that is)