pygame不会在函数内部进行blit?

max*_*hud 1 python pygame

我有一个代码块,它在函数之外工作,但不在内部.

我还确保必要的变量是全局的.

我可以使用chair.get_width()函数内部获得曲面的宽度,它工作正常,但screen.blit(chair, (10,10))由于某种原因我无法执行.我没有得到错误,它只是没有做任何事情......

这是我的脚本(它创建一个窗口,然后每100毫秒调用一个函数获取鼠标位置,旋转图像x度,然后将图像blit(或应该blit)到窗口):

    cif = "images/chair3.png"

    import pygame, sys
    from pygame.locals import *

    pygame.init()

    screen = pygame.display.set_mode((640,480),0,32)

    chair = pygame.image.load(cif).convert_alpha()

    pygame.time.set_timer(USEREVENT + 1, 100)

    def cursor(speed):
        global i
        global chair
                    global screen
        x,y = pygame.mouse.get_pos()
        x -= chair.get_width()/2
        y -= chair.get_height()/2

        if i < 360:
            i = i + 360/(1000/speed)
        else:
            i = 0

        orig_chair_rect = chair.get_rect()
        chair1 = pygame.transform.rotate(chair, i);
        rot_chair_rect = orig_chair_rect.copy()
        rot_chair_rect.center = chair1.get_rect().center
        chair1 = chair1.subsurface(rot_chair_rect).copy()

        print chair.get_width()

        screen.blit(chair1,(x,y))

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == USEREVENT + 1:
                cursor(50)
Run Code Online (Sandbox Code Playgroud)

bea*_*605 5

你需要使用pygame.display.flip()或者pygame.display.update(),如果你不这样做,屏幕将永远不会更新,因此你的椅子不会在屏幕上显示.

尝试过,它有效.如果它不适合您,请重新安装Pygame,然后重试.