0

I've been trying to figure out how to draw a texture within a circle with no luck.
For example, I have a red colored polygon that I drew on a surface called surf using pg.draw.polygon. Now I want to crop that surface into a circle (see images below)

From this
Example

To this.
Result

The way I was doing it was:

  • Create surf1 with a white circle and black background
  • Create surf2 with a white polygon and black background
  • Blit surf1 into surf2 with a multiply blend mode
  • Finally blit surf2 into the main game display surface

But this is too slow to even be considered a good idea... So is there an efficient way to create this?

Community
  • 1
  • 1
GSR
  • 49
  • 3
  • 2
    You say it's too slow, but are you changing your polygon every frame? If not, simply cache the resulting surface instead of blitting surf1 to surf2 every frame. – sloth Jan 07 '20 at 15:04
  • 1
    ... at least *"Create surf1 with a white circle and black background"* can be cached. – Rabbid76 Jan 07 '20 at 15:51
  • What part(s) of the 4 steps is taking the most time to execute? – martineau Jan 07 '20 at 17:09
  • I'm changing my polygon every frame since im simulating 2D lighting effects. So I can't save the poly in the cache. For some reason I didn't think of saving the circle in the cache. Thanks guys, its faster now but if anyone has a more efficient way for this I'll appreciate it. – GSR Jan 07 '20 at 17:52
  • It's difficult to give additional advice without seeing some of your code. A [mcve] would be beneficial, or you could look at [this answer](https://stackoverflow.com/a/582337/7675174) on profiling to investigate further yourself. – import random Jan 07 '20 at 23:25

0 Answers0