Managing Groups in pygame

前端 未结 2 1216
深忆病人
深忆病人 2020-12-22 05:53

I am creating a game where when you kill one mob, two more appears. I have it so when you kill one mob, the two others appear, but only one stays visible and behaves like it

2条回答
  •  暖寄归人
    2020-12-22 06:47

    1. Your code is erasing the Rect's width and height. If you want to use coordinates of the center, use:

      self.rect = self.image.get_rect()
      self.rect.center = location
      
    2. What is mobs.add() in update()? Because update is normally called every frame, and I'm guessing mobs is a sprite group.

    3. Your update:

      for Mob in mobs: Mob.moveV() Mob.moveH() screen.blit(Mob.image, Mob.rect)

    should be

    mobs.update()
    mobs.draw(screen)
    

    Check out this guys example https://stackoverflow.com/a/10418347/341744

提交回复
热议问题