I am trying to make a menu screen where the 'New Game' and 'Load Game' icons appear to have no box around them until the mouse is over them at which point they have an opaque blue box. I have yet to implement the mouse controls in the code as I currently cannot get the blue box to become opaque. Any advice would be great. Currently the screen is black when the code is run, however removing line 30 causes the screen to appear as it should but with no alpha values.
import random, pygame, sys
from pygame.locals import *
FPS = 30 # frames per second, the general speed of the program
WINDOWWIDTH = 1000 # size of the window's width in pixels
WINDOWHEIGHT = 600 # size of window's height in pixels
# R G B
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUEINVIS = (0, 0, 255, 255)
BLUEOP = (0, 0, 255, 128)
# Colors
TEXTCOLOR = WHITE
TEXTBOXCOLOR = BLUEINVIS
HIGHLIGHTCOLOR = BLUEOP
BASICFONTSIZE = 20
def main():
global FPSCLOCK, DISPLAYSURF, BASICFONT
pygame.init()
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
DISPLAYSURF = DISPLAYSURF.convert_alpha()
pygame.display.set_caption('Menu')
BASICFONT = pygame.font.Font('freesansbold.ttf', 50)
NEW_SURF, NEW_RECT = makeText('New Game', TEXTCOLOR, TEXTBOXCOLOR, WINDOWWIDTH / 2, WINDOWHEIGHT - (WINDOWHEIGHT * 3 / 8))
LOAD_SURF, LOAD_RECT = makeText('Load Game', TEXTCOLOR, TEXTBOXCOLOR, WINDOWWIDTH / 2, WINDOWHEIGHT - (WINDOWHEIGHT / 4))
DISPLAYSURF.convert_alpha()
while True: # main game loop
DISPLAYSURF.fill(RED)
DISPLAYSURF.blit(NEW_SURF, NEW_RECT)
DISPLAYSURF.blit(LOAD_SURF, LOAD_RECT)
for event in pygame.event.get(): # event handling loop
#if event.type == MOUSEBUTTONUP:
#if NEW_RECT.collidepoint(event.pos):
#elif LOAD_RECT.collidepoint(event.pos):
#if newRectObj.collidepoint(event.pos):
#newSurfaceObj = fontObj.render('New Game', True, TEXTCOLOR, HIGHLIGHTCOLOR)
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
FPSCLOCK.tick(FPS)
def makeText(text, color, bgcolor, x, y):
# create the Surface and Rect objects for some text.
textSurf = BASICFONT.render(text, True, color, bgcolor)
textRect = textSurf.get_rect()
textRect.center = (x, y)
return (textSurf, textRect)
if __name__ == '__main__':
main()