【发布时间】:2020-08-14 15:06:36
【问题描述】:
你去吧,我想尝试一个小 pygame,但我发现自己卡住了。
上下文
我创建了一个代表玩家的小精灵(使用 Piskelapp),看起来像:
player.png
然后以 jpg 格式添加我的背景。但是在启动游戏时,我的精灵被背景切割如下:
船没有放在背景前面,我越往上,它就越消失在背景后面……
这是我的代码:
import pygame
pygame.init()
# class user
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.pv = 100
self.__max_health = 100
self.attack = 2
self.velocity = 5
self.image = pygame.image.load('assets/player.png')
self.rect = self.image.get_rect()
self.rect.x = 400
self.rect.y = 500
# open game window
pygame.display.set_caption("Rocket 'n' Rock")
screen = pygame.display.set_mode((1080, 720))
# background import
bg = pygame.image.load('assets/bg.jpg')
# load player
player = Player()
running = True
# game mainloop
while running:
# bg apply
screen.blit(bg, (0,-400))
# screen update
pygame.display.flip()
# player image apply
screen.blit(player.image, player.rect)
# if player close the window
for event in pygame.event.get():
# *close event
if event.type == pygame.QUIT:
running = False
pygame.quit()
print("close game")
有人有小费吗?我想知道这不是文件格式问题吗? 谢谢你的时间
【问题讨论】:
标签: python python-3.x pygame