1

我想要做的是(0,390),(0,450),(610,390),(610,450) - 覆盖在一个名为(brick_tile)的平铺图像中。到目前为止,我只有这个:

import pygame
from pygame.locals import*

cloud_background = pygame.image.load('clouds.bmp')
brick_tile = pygame.image.load('brick_tile.png')

pink = (255, 64, 64)
w = 640
h = 480
screen = pygame.display.set_mode((w, h))
running = 1

while running:
    screen.fill((pink))
    screen.blit(cloud_background,(0,0))
    screen.blit(brick_tile,(0,450))
    pygame.display.flip()

    event = pygame.event.poll()
    if event.type == pygame.QUIT: sys.exit()
4

1 回答 1

2

要使用砖块平铺,您只需在循环中进行 blit、blit、blit:

import pygame
import sys
import itertools

cloud_background = pygame.image.load('clouds.bmp')
brick_tile = pygame.image.load('brick_tile.png')

pink = (255, 64, 64)
w = 640
h = 480
screen = pygame.display.set_mode((w, h))
running = 1

def setup_background():
    screen.fill((pink))
    screen.blit(cloud_background,(0,0))
    brick_width, brick_height = brick_tile.get_width(), brick_tile.get_height()
    for x,y in itertools.product(range(0,610+1,brick_width),
                                 range(390,450+1,brick_height)):
        # print(x,y)
        screen.blit(brick_tile, (x, y))
    pygame.display.flip()

while running:
    setup_background()    
    event = pygame.event.poll()
    if event.type == pygame.QUIT: sys.exit()
于 2012-01-07T15:25:50.847 回答