Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 316887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:25:30+00:00 2026-05-12T08:25:30+00:00

I’ve just started working with pygame and I’m trying to make a semi-transparent sprite,

  • 0

I’ve just started working with pygame and I’m trying to make a semi-transparent sprite, and the sprite’s source file is a non-transparent bitmap file loaded from the disk. I don’t want to edit the source image if I can help it. I’m sure there’s a way to do this with pygame code, but Google is of no help to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:25:30+00:00Added an answer on May 12, 2026 at 8:25 am

    I may have not been clear in my original question, but I think I figured it out on my own. What I was looking for turns out to be Surface’s set_alpha() method, so all I had to do was make sure that translucent images were on their own surface.

    Here’s an example with my stripped down code:

    import pygame, os.path
    from pygame.locals import *
    
    class TranslucentSprite(pygame.sprite.Sprite):
      def __init__(self):
        pygame.sprite.Sprite.__init__(self, TranslucentSprite.container)
        self.image = pygame.image.load(os.path.join('data', 'image.bmp'))
        self.image = self.image.convert()
        self.image.set_colorkey(-1, RLEACCEL)
        self.rect = self.image.get_rect()
        self.rect.center = (320,240)
    
    def main():
      pygame.init()
      screen = pygame.display.set_mode((640,480))
      background = pygame.Surface(screen.get_size())
      background = background.convert()
      background.fill((250,250,250))
      clock = pygame.time.Clock()
      transgroups = pygame.sprite.Group()
      TranslucentSprite.container = transgroups
    
      """Here's the Translucency Code"""
      transsurface = pygame.display.set_mode(screen.get_size())
      transsurface = transsurface.convert(screen)
      transsurface.fill((255,0,255))
      transsurface.set_colorkey((255,0,255))
      transsurface.set_alpha(50)
    
      TranslucentSprite()
      while 1:
        clock.tick(60)
        for event in pygame.event.get():
          if event.type == QUIT:
            return
          elif event.type == KEYDOWN and event.key == K_ESCAPE:
            return
        transgroups.draw(transsurface)
        screen.blit(background,(0,0))
        screen.blit(transsurface,(0,0))
        pygame.display.flip()
    
    if __name__ == '__main__' : main()
    

    Is this the best technique? It seems to be the most simple and straightforward.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.