Python Forum
Coloring a surface with transparency
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coloring a surface with transparency
#1
Hello all,

I am completely new here, I hope my question is correct here. I am programming a football manager game and would like to add a selection of a jersey color. The RGB colors are completely free selectable and a jersey should be colored in exactly this color.

My first approach was to load a white jersey with transparent background as Surface, and fill it with the desired color. However, I then only get a square box with the color, obviously the transparent pixels are also filled with the color. In addition, the black pixels (folds in the jersey) were also colored.

My goal is to have a jersey filled with the desired color, but still have a transparent background. I would be very happy about any hints or suggestions for solutions.

I am using Pygame.

Many greetings
Sandor
Reply
#2
A couple of links from duckduckgo search
https://stackoverflow.com/questions/3993...vert-alpha
https://www.codegrepper.com/code-example...background
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Thanks for the links, which unfortunately did not help much, but I actually found a first solution myself. I took a transparent jersey (only the outlines and single folds are visible) and checked with "get_at" every pixel for transparency, and if there is none, I colored the pixel with "set_at". At the end I drew the transparent jersey again and it looks very good.

But now I draw two images directly one after the other, once the colored jersey and once the transparent jersey. Is there a way to "save" a surface onto another surface, so that I have the finished jersey saved in a single variable?
Reply
#4
See attached the jersey, which consists of two graphics on the right side (excluding the pitch of course, the blue jersey is completely filled with the desired color and the transparent jersey is drawn above that to get that effect. Now I want these final graphic of the jersey saved in one variable).

   
Reply
#5
nevermind
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Surface and rectangle in pygame Fabrizio_fg 6 2,359 May-27-2023, 09:15 AM
Last Post: Fabrizio_fg
  [PyGame] Pygame is treating blob_group as a surface, when I need it to treat it as a Sprite. Swagford 1 1,321 Jan-24-2023, 09:58 PM
Last Post: metulburr
  Drawn line shift when that surface is copied to another in pygame Leo_Red 4 3,362 Feb-11-2021, 06:33 AM
Last Post: Leo_Red
  [PyGame] pygame.Surface.fill help Shemira 3 6,209 Nov-29-2019, 12:01 AM
Last Post: Shemira
  pygame.surface Graham 10 8,500 Nov-29-2018, 04:45 PM
Last Post: nilamo
  [PyGame] PLEASE HELP! TypeError: unsupported operand type(s) for +: 'pygame.Surface' and 'int' keyfive 1 5,311 Jun-19-2018, 01:20 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020