我的代码不工作,我不明白为什么,我正在使用模块PYGAME,我想在按下键“s时制作一个动画(三个图像)”。我的代码是:
import pygame, sys
from pygame.locals import *
from time import *
pygame.init()
ventana = pygame.display.set_mode((400,300))
pygame.display.set_caption("Hi!")
imgA = pygame.image.load("IMG/fan_azul.png")
imgB = pygame.image.load("IMG/fan_naranja.png")
imgC = pygame.image.load("IMG/fan_rojo.png")
listaImg = [imgA,imgB,imgC]
POS,aux,e = 0,1,0
picture = listaImg[POS]
posX,posY,fondo = 200,100,(50,50,50)
while True:
ventana.fill(fondo)
#ventana.blit(picture,(posX,posY))
for evento in pygame.event.get():
if evento.type == QUIT:
pygame.quit()
sys.exit()
elif evento.type == KEYDOWN:
if evento.key == K_s:
for e in range(0,3):
POS = e
picture = listaImg[POS]
ventana.blit(picture,(posX,posY))
print "TIEMPO MEDIDO: "+str(POS)
pygame.time.wait(1000)
pygame.display.update()
避免内部循环会挂起处理事件和其他绘图到框架,这一点很重要。请记住,您通常尝试每秒获得30到60帧,而您的K嫒s处理程序本身需要3秒。保持句柄事件、更新状态和绘制屏幕部分都是分开的。为了制作动画,我通常会这样做。在
相关问题 更多 >
编程相关推荐