我很难在pygame中迈出我的第一步。我只想在jpg背景前移动一张图片。
我在谷歌上搜索了几次,尝试了不同的方法。这是我能想到的“最近的”:
(但它仍然不起作用。)
有什么想法吗?
提前感谢!
尼科
import pygame
pygame.init()
display_width = 1600
display_height = 900
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
Player_width = 73
screen = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock()
background = pygame.surface(screen.get_size())
PlayerImg = pygame.image.load("C:\python\warrior1.png")
background_image = pygame.image.load("depositphotos_159346790-stock-photo-
forest-and-stones-2d-game.jpg")
background.blit(background_image)
screen.blit(background (0,0))
def Player(x,y):
gameDisplay.blit(PlayerImg,(x,y))
def game_loop():
x = (display_width * 0.45)
y = (display_height * 0.8)
x_change = 0
y_change = 0
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
if event.type == pygame.KEYDOWN:
[...]
x += x_change
y += y_change
Player(x,y)
if x > display_width - Player_width or x < 0:
gameExit = True
pygame.display.update()
clock.tick(60)
game_loop()
pygame.quit()
quit()发布于 2017-10-12 23:12:57
答案:
在while循环中,
screen.blit(background_image, (0,0))background.blit(background_image) screen.blit(background (0,0))替换background = pygame.surface(screen.get_size())screen.blit(background_image, (0,0))screen.blit(background_image, (0,0))替换gameDisplayPygame的有用提示:
查看错误消息并发布它们。
在pygame中使用*.png文件。它们可以是透明的。当图片重叠时,您看不到边缘。
https://stackoverflow.com/questions/46705240
复制相似问题