Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411522 Posts in 69377 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 28, 2024, 09:09:07 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[Pygame] Simple Example of Translucense Needed
Pages: [1]
Print
Author Topic: [Pygame] Simple Example of Translucense Needed  (Read 3830 times)
Alfonso Crawford
Level 0
**


View Profile
« on: April 19, 2009, 11:06:58 AM »

 Shrug I'm having some trouble getting a rectangle to be a little see-through. I'm only rendering basic Pygame-rectangles, right now, so I feel really silly. Any help is apprectiated!
Logged
george
Level 7
**



View Profile
« Reply #1 on: April 19, 2009, 11:16:09 AM »

I don't use Pygame but from a quick look at the docs you might just need to set the alpha value of the color you're drawing with, like

Color.a

      Gets or sets the alpha value of the Color.


With Pygame you need to set the color before you draw something, right?
Logged
Gold Cray
Level 10
*****


Gold Cray


View Profile WWW
« Reply #2 on: April 19, 2009, 11:29:55 AM »

This thing does some alpha stuff with a large black surface toward the end.
Logged
Alfonso Crawford
Level 0
**


View Profile
« Reply #3 on: April 19, 2009, 03:47:11 PM »

 Mock AngerHand Shake Right I already tried messing with the alpha-channel, via setting a pygame.Color-object's alpha to a myriad of values: I had no luck.

 Shrug I can't open TAR.GZ-files, on this PC. Damn.
Logged
george
Level 7
**



View Profile
« Reply #4 on: April 19, 2009, 08:39:02 PM »

OK, I got a minimal example working. However I noticed while doing so I still only have Pygame 1.8, while that Color module on their docs page is for 1.8.1.

Code:
import pygame, sys
from pygame.locals import *

pygame.init()

black = 0, 0, 0
surface = pygame.Surface((200, 100))

surface.fill((255, 255, 255))

surface.set_alpha(100)

screen = pygame.display.set_mode((600, 400))

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
    screen.fill(black)
    screen.blit(surface, (100, 100))
    pygame.display.flip()

You should see a grayish rectangle on a black screen. Play with surface.set_alpha to see the results. Note there seems to be at least two (maybe three?) different ways to set alpha values, for different reasons -- read up on the Surface module section of the docs. 

You can do a lot of stuff with Pygame but things like this are partly what made pyglet more attractive for me.
Logged
Alfonso Crawford
Level 0
**


View Profile
« Reply #5 on: April 25, 2009, 07:56:06 PM »

 Beer! I apologize for taking so long to express my thanks, george! I never would have guessed to overlap surfaces, as opposed to my direct-draw approach! Testing is going very smoothly, now. Thanks!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic