动画问题仍然存在

时间:2016-06-16 20:23:24

标签: python animation pygame

代码

#Importing files/modules
import pygame
import random

#Colors

BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)
ORANGe = (255, 115, 0)
YELLOW = (242, 255, 0)
BROWN = (115, 87, 39)
PURPLE = ( 298, 0, 246)
GRAY = ( 168, 168, 168)
BLUE = ( 0, 0, 255)
GROUND = (156,168,91)
pygame.init()

#Screen
screenx = 1000
screeny = 700
screentotal = [screenx,screeny]
screen = pygame.display.set_mode(screentotal)

#Caption
pygame.display.set_caption("Animation attempt one")

#Variables
x = 500
y = 1000
a = 0
b = 500
c = 1500
d = 1000
#Booleans
go = True
#Graphics
one = pygame.image.load("uno.jpg").convert()
two = pygame.image.load("dos.jpg").convert()
three = pygame.image.load("tres.jpg").convert()

#Position
position = [0,0]
#Time management
clock = pygame.time.Clock()
FPS = 60
animation_timer = pygame.time.Clock()
animation_time = 0
screen.fill(GREEN)
#MAIN LOOP _________________________________________________________

done = False

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True



    if go:
        animation_timer.tick()
        animation_time += animation_timer.get_time()
        if animation_time < x and  animation_time > a:
            screen.blit(one,position)
            x += 1000
            a += 1000
        if animation_time < y and animation_time> b:
            screen.blit(two,position)
            y += 1000
            b += 1000
        if animation_time < c and animation_time > d:
            screen.blit(three,position)
            c += 1000
            d += 1000






    #Flip the display
    pygame.display.flip()
    clock.tick(FPS)
#Quit
pygame.quit()

问题

我的代码应该在动画中绘制3个图像,并逐步添加abcd以使其在动画中循环。当我只使用if语句中的两个第一个图像时它可以正常工作。但是当我添加第3个if图像语句时,它通过每秒显示3个图像来显示动画,但是在第一次动画后第3个图像没有弹出,只有前2个图像有效。我试过改变时间和变量,但它不起作用。

感谢您提供的任何帮助:)

我知道这是一种尝试动画的非常复杂的方式,但这是我最喜欢的方式。感谢

1 个答案:

答案 0 :(得分:0)

好的,我解决了。事实证明,由于事件的数量,我不得不将最后一张图像增加2000而不是1000.所以c和d需要加2000而不是1000。