gpt4 book ai didi

python - 如何在 python/pygame 中覆盖图 block (图像)中的区域?

转载 作者:行者123 更新时间:2023-12-01 06:04:35 39 4
gpt4 key购买 nike

我想要做的是 (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()

最佳答案

要使用砖 block 进行平铺,您只需循环进行 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()

关于python - 如何在 python/pygame 中覆盖图 block (图像)中的区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8770484/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com