Python Pygame中的短动画课程?

Python Pygame中的短动画课程?,python,class,object,python-2.7,pygame,Python,Class,Object,Python 2.7,Pygame,我几乎还不知道如何使用课堂。我只需要做一个18帧的动画,并有能力做它的任何地方(25次)在5x5网格。关于如何做到这一点有什么想法吗 不管怎样,这就是我到目前为止所做的: class showRectangles: def __init__(self): pass def flipcard(self): while showrect: pygame.draw.rect(window,black,[self.position,75*scale,75*scale]

我几乎还不知道如何使用课堂。我只需要做一个18帧的动画,并有能力做它的任何地方(25次)在5x5网格。关于如何做到这一点有什么想法吗

不管怎样,这就是我到目前为止所做的:

class showRectangles:
  def __init__(self):
    pass
  def flipcard(self):
    while showrect:
      pygame.draw.rect(window,black,[self.position,75*scale,75*scale])
    self.blitoptions = self.image,self.position,[[55,self.frame,0],[75*scale,75*scale]]
    window.blit(pygame.transform.smoothscale(self.blitoptions,75*scale).convert_alpha())
    if self.flipping and self.frame != 18:
      self.frame += 1
    else:
      self.flipping = False

class boardCard(showRectangles):

  def __init__(self,pos):
    self.position = pos
    self.rect = Rect(self.position[0]*scale,self.position[1]*scale,self.position[0]+75*scale,self.position[1]+75*scale)
    self.flipping = False
    self.frame = 0
    self.image = themedb["default"]["images"]["flipanimation"]


  # def getrect(self):
  #   return pygame.rect(int(self.position[0]),int(self.position[1]),int(self.position[0])+75*scale,int(self.position[1])+75*scale)
变量:

Showrect显示可单击的区域,作为一种“调试视图”

比例是调整窗口大小和窗口上图像的大小

主题B是游戏的一组主题。“FlipAnimation.png”存储在这里。

您阅读了吗?他们对课程有很好的解释

我不确定你想完成什么,但你似乎有一个矩形网格,点击后,你想用动画翻转卡片

您需要定义一个类MyRectangle,该类将具有方法
\uuuu init\uuuu
draw
update
。下面是一个简短的例子:

class Card:
    def __init__(self,pos):
        self.flipping = false
        self.images = loadImages()
        self.frame = 0
        self.pos = pos
    def flip():
        self.flipping = true
    def update():
        if self.flipping:
            self.frame += 1
            self.frame %= len(self.images)
    def draw(screen):
        screen.blit(self.images[self.frame],self.pos)
您的主循环代码如下所示:

cards = []
for x in range(10):
   for y in range(10):
      cards.append(Card((x*10,y*10)))
while not finished:
    for card in cards:
        card.draw(screen)
        card.update()
#somewhere in the event loop:
    card.flip()

我试着阅读,请一位朋友解释,并在YouTube上观看了几个人的解释。我知道它们是如何工作的,也知道它们为什么工作,但由于某种原因,我不知道如何将它们应用到我正在努力做的事情中。谢谢你的帮助。把它当作更大的东西的一部分。每个对象都有被调用以更改其状态或响应操作的方法。在这种情况下,卡可能位于名为Board的类中,该类将有一个卡列表。@Kweb123单独调用什么?你能详细说明一下吗?每张卡片。这25张牌中的每一张都需要在不同的时间翻动,但目前的设置是一次翻动所有的牌,不是吗?