我試圖爲我的遊戲顯示一個背景圖片,但是當我點擊它時,它只會在黑色背景的屏幕上顯示我的主要可玩角色。任何人都可以幫助我解決這個問題。爲什麼我不能在字符圖像曝光的同時使背景圖像呈現?
下面的代碼:
import sys, pygame, os
pygame.init()
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption("Game")
size = width, height = 320, 240
xREVERSEspeed = [-2, 0]
xspeed = [2, 0]
screen = pygame.display.set_mode(size)
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 1:
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()
這是怎麼回答有什麼不同? – 2013-03-06 16:58:48
我想我們都在同一時間回覆 – tsa 2013-03-06 22:45:34
我已經提前10分鐘回覆。 – 2013-03-07 12:58:59