使用libavg的Python中的“闪烁”动画

2024-05-02 05:04:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个使用libavg和一系列RectNodes的项目。我要做的是播放一个动画,使每个节点亮起2,5秒,然后淡出。每次单击其中一个节点时,该特定节点应发生相同的动画。在

我使用的是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

我的眨眼密码是:

^{pr2}$

我用的是:

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

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

对我帮助不大,谢谢你的帮助。在


Tags: 项目selfnode节点defcount动画print
1条回答
网友
1楼 · 发布于 2024-05-02 05:04:47

问题是动画开始()是非阻塞的。 而不是只在动画完成后返回,而是立即返回并同时执行动画。这意味着您的函数同时启动两个动画取消应设置动画的节点的链接。在

因此,您应该使用可以赋予动画的结束回调来触发一个又一个步骤。然后blink函数可以如下所示:

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)

^{pr2}$

相关问题 更多 >