我有一张 600x1000 的图片,我想使用 pygame 将图片的底部涂到我的 600x600 窗口上



在游戏中,我们的角色跳上平台以移动得更高。我的游戏分辨率是600x600。我有一张图片,它将成为我的背景,分辨率为600x1000。我正在尝试设置一个背景,随着我们走得更高,背景会逐渐移动或变化。因此,当我变高时,背景显示的不是原始图片的底部(Y 轴 400-1000(,而是显示例如图片的中间部分(Y 轴 200-800(。 到目前为止,我还没有找到一种方法 从 600x600 图像中抹黑 600x1000 图像。这就像我想剪掉原始图片的上半部分,使其适合。你能帮我这个吗?

如果我没有正确解释,我很抱歉。如何从较大尺寸的图像中分辨出未失真的较小尺寸的图像。我想到的背景应该看起来像一款名为"Happy Jump"的安卓游戏。

感谢您的阅读。 祝你今天开心。

在此处输入图像描述

import pygame
pygame.init()
run = True
surf = pygame.display.set_mode((600, 600))
img = pygame.image.load('image.jpg')
down = -400
center_of_screen = 300
maximum_limit_of_down = 0
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((40, 40))
self.image.fill((255, 0, 0))
self.rect = self.image.get_rect()
self.rect.center = (300, 570)
self.isJump = False
self.jumpCount = 10
def update(self):
global down
key = pygame.key.get_pressed()
if key[pygame.K_UP] and not self.isJump:
self.isJump = True
if self.isJump:
if self.rect.y > center_of_screen or (down >= maximum_limit_of_down):
if self.jumpCount >= 0:
self.rect.y = self.rect.y - (self.jumpCount ** 2) * 0.5
self.jumpCount -= 1
else:
self.jumpCount = 10
self.isJump = False
if down >= maximum_limit_of_down:
down = maximum_limit_of_down
else:
if self.jumpCount >= 0:
down = down + (self.jumpCount ** 2) * 0.5
self.jumpCount -= 1
else:
self.jumpCount = 10
self.isJump = False

player = Player()
all_sprite = pygame.sprite.Group()
all_sprite.add(player)
clock = pygame.time.Clock()
while run:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
surf.fill((0, 0, 0))
surf.blit(img, (0, down))
all_sprite.update()
all_sprite.draw(surf)
pygame.display.update()

这将对您有所帮助,对不起,我使用了我发现的任何图像

最新更新