Your blits were copying the source to positions outside the target surface.
I always suspect this if I can't see my graphics. You can insert statements
like "dlgsurface.get_rect().collidepoint(choicerect.topleft)" or "print
dlgsurface.get_rect().colliderect(choicerect)" to tell whether the source
rect intersects the target rect.
I has a sneaking suspicion about the alpha problem and it paid off. Someone
who understands the internals of color alphas and surface alphas would have
to explain the why. :)
#Create menu surface
dlgsurface = pygame.Surface((xsize,ysize)).convert()
##change
# dlgsurface.fill(color)
dlgsurface.fill(*color[3:])
dlgsurface.set_alpha(color.a)
dlgrect = dlgsurface.get_rect(center=self.rect.center)
##new
drawrect = dlgsurface.get_rect()
cursor_rect = []
ypos = border
for option in options:
##change
# choicerect = option.get_rect(centerx=dlgrect.centerx, \
# top=dlgrect.top + ypos)
choicerect = option.get_rect(centerx=drawrect.centerx, \
top=drawrect.top + ypos)
dlgsurface.blit(option, choicerect)
##change
#
cursor_rect.append(cursor[0].get_rect(centery=choicerect.centery, \
# left = dlgrect.left+border))
cursor_rect.append(cursor[0].get_rect(
centery=dlgrect.top+choicerect.centery,
left=dlgrect.left+border))
ypos += option.get_height() + sep
Gumm
Sat, Oct 9, 2010 at 11:23 AM, Julian Marchant <[email protected]> wrote:
> Attached is the file in question, comet_fighter.py (version 0.1.0.5).
>
> Game.menu() is supposed to show a menu. It takes the following arguments:
>
> options, cursor, anim_wait, color=pygame.Color(0,0,0,155), border=16, sep=8
>
> "options" is a list of surfaces used for the menu choices. "cursor" is a
> list of surfaces which animate to create the selection cursor. "anim_wait"
> is the time (in milliseconds) between each frame of animation for the
> cursor. "color" is a pygame.Color object with an alpha value, which is used
> to set the color and alpha of the back of the dialog. "border" indicates the
> number of pixels around the menu box, and "sep" is the number of pixels
> between each menu choice.
>
> The problem is, it doesn't seem to be working like it should.
>
> I tried calling Game.menu() in order to test it. It sort of worked, but not
> really. There are a few issues.
>
> First, the back of the menu is always fully opaque or fully transparent.
> Partial transparency isn't working.
>
> Second, and more importantly, the menu choices aren't showing up.
>
> Everything else seems to be working perfectly. I scanned my code at least
> twice, and I couldn't find anything wrong with it. Perhaps someone else can
> have better luck, or perhaps I'm doing something wrong?
>
>