pygame屏幕。模式更改后变黑

时间:2018-12-26 18:30:23

标签: python pygame

我想以不同的模式显示不同的pygame表面。我的第一个模式可以工作,但后续模式中的表面是黑色的。我不明白为什么。

import pygame
import pygame.gfxdraw

screenWidth = 800
screenHeight = 800

path = (r"C:\Users\eeifler\Pictures\code drawings\35\trace.PNG")

imageFile = pygame.image.load(path)
imageFile = pygame.transform.scale(imageFile, (screenWidth,screenHeight))

pygame.init()

screen = pygame.display.set_mode((screenWidth, screenHeight))

running = True
quadrent = 1

while running:
    screen.blit(imageFile, (0,0))
    cropped = pygame.Surface((screenWidth//2, screenHeight//2))      


    if quadrent == 1:
        cropped.blit(screen, (0,0), pygame.Rect( 0, 0, screenWidth//2, screenHeight//2))

        bottomLeft = pygame.transform.flip(cropped, False, True)
        screen.blit(bottomLeft, pygame.Rect(0,screenHeight//2,screenWidth//2,screenHeight//2))

        topRight = pygame.transform.flip(cropped,True,False)
        screen.blit(topRight, pygame.Rect(screenWidth//2,0,screenWidth//2, screenHeight//2))

        bottomRight = pygame.transform.flip(cropped, True, True)
        screen.blit(bottomRight, pygame.Rect(screenWidth//2,screenHeight//2, screenWidth//2, screenHeight//2))

    if quadrent == 2:
        cropped.blit(screen, (screenWidth//2,screenHeight//2), pygame.Rect( screenWidth//2, 0, screenWidth//2, screenHeight//2))

        topLeft = pygame.transform.flip(cropped, False, True)
        screen.blit(topLeft, pygame.Rect( 0, 0, screenWidth//2, screenHeight//2))

        bottomLeft = pygame.transform.flip(cropped, True, True)
        screen.blit(bottomLeft, pygame.Rect(0,screenHeight//2,screenWidth//2,screenHeight//2))

        bottomRight = pygame.transform.flip(cropped, True, True)
        screen.blit(bottomRight, pygame.Rect(screenWidth//2,screenHeight//2, screenWidth//2, screenHeight//2))



    #if quadrent == 3:
        #cropped.blit(screen, (0,0), pygame.Rect( 0, screenHeight//2, screenWidth//2, screenHeight//2))
    #if quadrent == 4:
        #cropped.blit(screen, (0,0), pygame.Rect(screenWidth//2,screenHeight//2, screenWidth, screenHeight))

    key = pygame.key.get_pressed()

    if key[pygame.K_a]:
        quadrent = 1
    if key[pygame.K_s]:
        quadrent = 2
    if key[pygame.K_d]:
        quadrent = 3
    if key[pygame.K_f]:
        quadrent = 4

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    pygame.display.flip()

1 个答案:

答案 0 :(得分:0)

啊。我误解了如何使用surface.blit

cropped.blit(screen, (screenWidth//2,screenHeight//2), pygame.Rect( screenWidth//2, 0, screenWidth//2, screenHeight//2))

应该是

cropped.blit(screen, (0,0), pygame.Rect( screenWidth//2, 0, screenWidth//2, screenHeight//2))

分配给新曲面的左上角。确定裁剪的部分在pygame.Rect()部分中进行。