2012-06-28 2 views
0

저는 libavg와 일련의 RectNodes를 사용하여 프로젝트 작업을하고 있습니다. 내가하려고하는 일은 각 노드가 2,5 초 동안 흰색으로 점등 된 다음 다시 사라지는 애니메이션을 재생하는 것입니다. 노드 중 하나를 클릭 할 때마다 해당 특정 노드에 대해 동일한 애니메이션이 발생해야합니다.libavg로 파이썬에서 "깜박임"애니메이션

나는 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)