【问题标题】:Pygame screen display issuePygame屏幕显示问题
【发布时间】:2018-05-18 14:21:26
【问题描述】:
import pygame
pygame.init()


display_width = (640)
display_height = (480)

title = pygame.display.set_caption("test")
IMG = pygame.image.load("image.png")
screen = pygame.display.set_mode((display_width,display_height))

screen.blit(IMG,(1,1))

pygame.display.update()

每当我使用 pygame 时,即使是像这样的简单显示也会对我产生偏差。它在我的显示屏中间显示 0,0,我不知道为什么。基本上,它显示 - x 轴上的 x 值有帮助! 我正在使用 python 2.7,这似乎不是编码问题,而是其他问题。请帮忙!太棒了

【问题讨论】:

    标签: python pygame display


    【解决方案1】:

    我无法在 Python 2.7.12 中使用上述代码复制您的问题,图像是红色的 50 像素正方形:

    这是一个扩展演示,它将根据单击的鼠标按钮在光标位置周围绘制图像。也许这会帮助你实现你所追求的行为。

    import pygame
    
    if __name__ == "__main__":
        pygame.init()
        screen_width, screen_height = 640, 480
        screen = pygame.display.set_mode((screen_width, screen_height))
        pygame.display.set_caption('Blit Demo')
        clock = pygame.time.Clock() #for limiting FPS
        FPS = 10
        exit_demo = False
        # start with a white background
        screen.fill(pygame.Color("white"))
        img = pygame.image.load("image.png")
        width, height = img.get_size()
        pos = (1,1)  # initial position to draw the image
        # main loop
        while not exit_demo:
            for event in pygame.event.get():            
                if event.type == pygame.QUIT:
                    exit_demo = True
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        # fill the screen with white, erasing everything
                        screen.fill(pygame.Color("white"))
                elif event.type == pygame.MOUSEBUTTONUP:
                    if event.button == 1:  # left
                        pos = (event.pos[0] - width, event.pos[1] - height)                   
                    elif event.button == 2: # middle
                        pos = (event.pos[0] - width // 2, event.pos[1] - height // 2)
                    elif event.button == 3: # right
                        pos = event.pos
    
            # draw the image here
            screen.blit(img, pos)
            # update screen
            pygame.display.update()
            clock.tick(FPS)
        pygame.quit()
        quit()
    

    【讨论】:

      猜你喜欢
      • 2017-02-16
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      相关资源
      最近更新 更多