我正在尝试为我的游戏显示背景图像,但是当我对其进行 blit 时,它只会在屏幕上显示我的主要可玩角色,并带有黑色背景。谁能帮我解决这个问题。
这是代码:
import sys, pygame, os
pygame.init()
size = width, height = 320, 240
xREVERSEspeed = [-2, 0]
xspeed = [2, 0]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Game")
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
ball = pygame.image.load("turret.png").convert_alpha()
background = pygame.image.load("scoreframe.png").convert()
ballrect = ball.get_rect(center=(160, 231))
BACKGROUNDrect = background.get_rect()
clock = pygame.time.Clock()
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
print "I've pressed the LEFT arrow button."
ballrect = ballrect.move(xspeed)
print ballrect
if event.key == pygame.K_RIGHT:
print "I've pressed the RIGHT arrow button."
ballrect = ballrect.move(xREVERSEspeed)
print ballrect
screen.blit(ball, ballrect, background, BACKGROUNDrect)
pygame.display.flip()