如何使用Yaml在Pygame中加载动画?

时间:2019-06-19 10:59:08

标签: python pygame yaml

如果您观看此视频https://www.youtube.com/watch?v=aUCyfdzP-i8 您可以在1:52上看到Yaml制作的动画,但我无法加载此动画。怎么做?他的代码在视频下面。

这是我尝试过的:

- door:
      animation: oncollision
      tpf: 5
      condition: "if main_game.keyboard.is_clicked(K_DOWN):     self.timer = 1"
      commands: "
      \nself.animation_loop = False
      \nif self.animation_done:
      \n      level = Level('level_pub.map',     Vector(159*self.scale_factor,150*self.scale_factor))
      \n      main_game.list_update = [level]
      \n      main_game.list_draw = [level]
            "
      image: ["moving_objects/door","door"]
      position: [949,892]
      scale: [12,20]

仅当我运行程序时,它才表示错误:     无法加载图片:data / images / moving_objects / door / door13.png 但我从未告诉过要加载13张图像。如何仅加载12张图像?

if "image" in self.level[obj]:
                if isinstance(self.level[obj]["image"],     basestring):
                    obj_image =     load_png(self.level[obj]["image"])
                elif isinstance(self.level[obj].   ["image"][1], list):
                    tile_scale_x = self.level[obj].   ["image"][1][0]
                    tile_scale_y = self.level[obj].   ["image"][1][1]
                    tileset =     load_tile_table(self.level[obj]["image"][0], tile_scale_x,     tile_scale_y)
                    tile_pos_x = self.level[obj].   ["image"][2][0]
                    tile_pos_y = self.level[obj]["image"][2][1]
                    obj_image = tileset[tile_pos_x][tile_pos_y]

0 个答案:

没有答案