2012-06-28 46 views
0

我正在使用libavg和一系列RectNodes處理項目。我試圖做的是播放動畫,使每個節點點亮2.5秒白色,然後淡出。每次單擊其中一個節點時,該特定節點都會發生相同的動畫。使用libavg在Python中「閃爍」動畫

我使用AVGApp類,並與RectNode ID列表以及它們是如何多次應該亮起來,像(ID1,2)

def playAnim(self, animarr): 
     for i in range(0, len(animarr)): 
      i, count = animarr[i] 
      sid = "r" + str(i) 
      node = g_player.getElementByID(sid) 
      while count > 0: 
       self.blink(node) 
       count -= 1 
     return 

和我是眨眼代碼:

def _enter(self): 
    (some other stuff here) 

    print "Let's get started!" 
    self.playAnim(self.animArr) 
    print "Your turn!" 

任何幫助是極大的讚賞,該libavg參考是沒有幫助:

def blink(self, node): 
    pos = node.pos 
    size = node.size 

    covernode = avg.RectNode(pos=pos, size=size, fillopacity=0, 
          parent = self._parentNode, fillcolor="ffffff", 
           color="000000", strokewidth=2) 

    self.animObj = LinearAnim(covernode, 'fillopacity', 1000, 0, 1) 
    self.animObj.start() 
    self.animObj = LinearAnim(covernode, 'fillopacity', 1000, 1, 0) 
    self.animObj.start() 
    covernode.unlink(True) 
    return 

我與調用它我很多。

回答

2

問題是anim.start()是非阻塞的。 而不是隻在動畫完成後返回,它會立即返回並且動畫將同時執行。這意味着您的功能同時啓動兩個動畫取消鏈接應該動畫的節點。

因此,您應該使用可以賦予動畫的結束回調來一步接一步地觸發。然後,閃爍功能看起來是這樣的:

def blink(self, node): 
    pos = node.pos 
    size = node.size  
    covernode = avg.RectNode(pos=pos, size=size, fillopacity=0, 
          parent = self._parentNode, fillcolor="ffffff", 
          color="000000", strokewidth=2) 

    fadeOutAnim = LinearAnim(covernode, 'fillopacity', 1000, 1, 0, False, 
          None, covernode.unlink) 
    fadInAnim= LinearAnim(covernode, 'fillopacity', 1000, 0, 1, False, 
           None, fadeOutAnim.start) 
    fadInAnim.start() 

如果您希望節點留白一定量的時候,你必須插入使用一個WaitAnim或player.setTimeout()又邁進了一步。 (https://www.libavg.de/reference/current/player.html#libavg.avg.Player)

def blink(self, node): 
    pos = node.pos 
    size = node.size  
    covernode = avg.RectNode(pos=pos, size=size, fillopacity=0, 
          parent = self._parentNode, fillcolor="ffffff", 
          color="000000", strokewidth=2) 

    fadeOutAnim = LinearAnim(covernode, 'fillopacity', 1000, 1, 0, False, 
          None, covernode.unlink 
          ) 
    fadInAnimObj = LinearAnim(covernode, 'fillopacity', 1000, 0, 1, False, 
           None, lambda:self.wait(500, fadeOutAnim.start) 
          ) 
    fadInAnimObj.start() 


def wait(self, time, end_cb): 
    avg.Player.get().setTimeout(time, end_cb)