1
\$\begingroup\$

I'm working with the C# wrapper for SDL and am stumped at how to handle this issue. Right now I have a simple Actor that spawns N number of bullets from himself and fires them circularly outward. The problem is that the last bullet renders on top of everything and looks awful.

Below is a picture with the last bullet painted blue with the shooting actor in the center (also blue). enter image description here

I was hoping to try and figure out how to get it above the 2nd to last bullet while the bottom half is under the first. The closest thing I could find on this subject was this CSS article. The problem though is that it is solving the issue with 3D and I am working in pure 2D. Here's a picture from the article of what I am trying to achieve.

enter image description here

I can't tell if this is something easy or really hard to achieve, but it appears I definitely don't know what to search for because even that one article I found, I just happened to stumble upon it by looking at Google Images.

So I guess my question is, what is the proper term for this and what are the tricks to trying to solve this in a 2D space?

\$\endgroup\$
2
  • \$\begingroup\$ Hack it. Split #0 in two halves, horizontally. Draw the top half first, then #11, then #10, ..., then #1, and then finally the second/bottom half of #0. I don't have a clue on how this would be done in sdl. \$\endgroup\$
    – Vaillancourt
    Commented Mar 21, 2019 at 0:37
  • \$\begingroup\$ @AlexandreVaillancourt I thought about that. Unfortunately, I am currently looking at this as a particle effect and dynamic where they might overlap by just a few pixels and they do currently as they spawn at the center of the actor as they move outward =/ Guess once I really need to clean it up, I can try to mask out the first bullet, but am afraid of the performance since this is a bullet hell game. \$\endgroup\$
    – TyCobb
    Commented Mar 21, 2019 at 0:48

1 Answer 1

2
\$\begingroup\$

This can be done by using SDL_SetClipRect. This'll basically only allow you to render inside the provided rectangle.

First draw the first 3/4 of the circles. If you started at the circle farthest to the right, this would leave you with a circle, where the top right quarter is missing.

enter image description here

Place the rectangle so that the left side of it lines up with the left side of the window, the top side lines up with the top, the right with the right and the bottom with the top of the second circle (y is the center of the second circle minus radius).

enter image description here

Draw the rest of the circles and to make sure everything lines up, draw the first one again. Since the clipping rectangle stops the circles from touching the second circle, they won't get above it.

\$\endgroup\$
1
  • \$\begingroup\$ Nice. I will give this a shot. I like this because it shouldn't be much (if any) of a performance hit and even if the outcome isn't pixel perfect, it shouldn't really be noticeable due to the speed and is already 99% better than what I render now. Thanks a ton! \$\endgroup\$
    – TyCobb
    Commented Mar 21, 2019 at 3:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .