在Pygame中带有图像列表的动画 [英] Animation in with a list of images in Pygame
问题描述
我一直很迷恋Flappy Bird克隆。如果您不了解游戏,那么当小鸟飞起来时就会发生动画。
I've been suck on my Flappy Bird clone. If you don't know the game, there is an animation that happens when the bird fly up.
以下是我如何尝试制作动画的一般思路:
self.x和self.y指向照片的位置
Here is a general idea of how I tried to do an animation: self.x and self.y refer to the position of the photo
这是我的代码:
def move_up_animation(self):
#list of bird photos to animate
animation_list = ['1.tiff','2.tiff','3.tiff','4.tiff','5.tiff']
for i in range(len(animation_list)):
if self.y - 1 > 0: # checks if the bird is within the frame
self.y = self.y - 1 #changes the bird's, allowing the bird to fly up
self.image = pygame.image.load(animation[i])
self.display_image()
我尝试过time.sleep(1)
I tried time.sleep(1) but it doesn't work.
我不知道这段代码是如何工作的:
I have no idea how this code works:
for i in range(5):
print(i)
time.sleep(1)
推荐答案
我不知道这段代码的工作原理:
"I have no idea how this code works":
for i in range(5):
print(i)
time.sleep(1)"
它的工作原理是: for
将查看它是在范围(0,5)上的是真还是假变量I,而不是5.如果为true,则运行print命令。
It works like that: for
will see if it's a true or false variable I on the range (0, 5), not 5. If it is true will run the print command.
time.sleep
我不知道如何
要移动小鸟,您需要增加和减小y轴,以便飞行和保持重力。我希望您知道这样做(就像按它会飞的空间一样,不要按它会掉下来的东西)。
To move the bird you need to add and decrease the y axis, for both flying and gravity. I hope you know to do do it (like pressing space it flies, no pressing it falls).
代替if可以使用if。
Instead of using for you can use if.
if K_SPACE:
y -= 12
这将使鸟的y轴增加12。我希望这将像原始的跳跃游戏一样。要使其变得平滑,可以在for内使用.tick()模块,但我认为这确实是不必要的。
It will make the y-axis of the bird increase by 12. I hope that will be like the original jump game. To make it smooth you can use .tick() module inside the for, but I think it is really unnecessary.
这篇关于在Pygame中带有图像列表的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!