Pygame代码用闪烁的鼠标滞后

时间:2017-05-17 01:10:24

标签: python pygame python-3.6

所以我正在尝试创建一个按钮,只需设置背景图像(通过blitting一个在另一个上)。但是,我认为这段代码应该有效:

place = True
action = None
def startup(action):
    while place == True:
    gameDisplay.blit(imgstr, (0, 0))
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    if 500+140 > mouse[0] > 500 and 140+150 > mouse[1] > 140:
        pygame.draw.rect(gameDisplay, black, (500,140,150,150))
        pygame.mouse.set_cursor(*pygame.cursors.tri_left)
        if click[0] == 1 and action != None:
            if action == "play":
                game_loop()
    else:
        pygame.draw.rect(gameDisplay, white, (500,140,150,150))
        pygame.mouse.set_cursor(*pygame.cursors.arrow)
def game_loop():
    while place == True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RCTRL:
                    pygame.quit()
                    quit()
        gameDisplay.blit(imgm, (0, 0))

        pygame.display.update()
startup("play")

但是pygame只是用黑屏启动,鼠标闪烁,直到Windows停止它,因为它没有响应。

1 个答案:

答案 0 :(得分:0)

如果有人想知道,我已成功解决了以下代码的问题:

import pygame

pygame.init()

screen = pygame.display.set_mode([852,441])

pygame.display.set_caption("test")

keep_going = True
mousedown = True

background_image = pygame.image.load("start.jpg")

main_img = pygame.image.load("chromos.png")

colorkey = background_image.get_at((0,0))
background_image.set_colorkey(colorkey)
black = (0,0,0)
red = (255,0,0)

picx = 0
picy = 0

main_picx = 0
main_picy = 0

screen.fill(red)

while keep_going:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keep_going = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            if pygame.mouse.get_pos() > (500, 500) and pygame.mouse.get_pos() < (700, 700):
                picx = 5000
                picy = 5000
                mousedown = False
        print(event)
    if mousedown:
        screen.blit(background_image, (picx,picy))
    else:
        screen.blit(main_img, (main_picx, main_picy))
    pygame.display.update()
pygame.quit()
quit()