app2图片应该从右侧滑入但不会。两张图片均为1920x1080。我该如何解决这个问题?
import pygame, sys
from pygame.locals import*
number=1
screen = pygame.display.set_mode((1920,1080))
app1=pygame.image.load("app1.jpg").convert()
app2=pygame.image.load("app2.jpg").convert()
clock = pygame.time.Clock()
app1x=0
app2x=1920
loop=True
while loop:
screen.fill( (0,0,0) )
for event in pygame.event.get():
if event.type==KEYDOWN:
if event.key==K_RIGHT:
print ("right")
number=number+1
if event.type==pygame.QUIT:
print("l")
loop=False
pygame.quit()
quit()
screen.blit(app1, (app1x,0))
if number==1:
screen.blit(app1, (app1x,0))
if number==2:
if app2x==0:
print ("d")
else:
app2x=app2x-1
app1x=app1x-1
clock.tick(20)
pygame.display.update()
答案 0 :(得分:0)
您只是更新屏幕的一部分,以及不在while循环内部的时钟。以下是使用您的代码的示例:
while loop:
screen.fill( (0,0,0) )
for event in pygame.event.get():
if event.type==KEYDOWN:
if event.key==K_RIGHT:
print ("right")
number=number+1
if event.type==pygame.QUIT:
print("l")
loop=False
screen.blit(app1, (app1x,0))
if number==1:
screen.blit(app1, (app1x,0))
if number==2:
if app2x==0:
print ("d")
else:
app2x=app2x-1
app1x=app1x-1
pygame.display.flip()
clock.tick(20)
pygame.quit()
另外,请注意我在整个pygame.quit()
循环后移动while
的方式。这样,当loop
为false并结束时,pygame也会退出。移动pygame.quit()
只是为了清理代码,并且不会显着影响代码。
干杯!