2015-06-27 47 views
1

我想用一個運行一次然後停止的gif動畫製作一個kivy程序。 我將anim_loop設置爲1,但它一直運行一遍又一遍。 下面是代碼:Kivy Gif動畫運行頻率過高

Root = Builder.load_string(''' 
    Image: 
    source: 'streifen1.gif' 
    size_hint_y: 1 
    anim_loop: 1 
''') 


class TTT(App): 
def build(self): 
    Window.clearcolor = (0, 0.5, 1, 1)# sets the backgroundcolor 
    return Root #returnst the kv string and therefore the root widget` 
+0

您使用的是kivy 1.9嗎?你是否可以嘗試一下你的圖片而不是一個gif,這可能會更好地支持? – inclement

+0

@inclement我該如何做到這一點,在文檔中沒有任何關於它的內容:http://kivy.org/docs/api-kivy.uix.image.html?highlight=image#kivy.uix.image – Gilgamesch

+0

製作一個包含你的圖像的zip文件,並將圖像源指向該文件名。 – inclement

回答

2

anim_loop屬性應該在Kivy 1.9.0工作,如果你使用的是舊版本,然後再考慮升級。

還有一種方法。您可以使用下面的代碼停止動畫:

myimage._coreimage.anim_reset(False) 

要停止的動畫有人打一次後觀察texture屬性格式。它將在加載每個幀後進行更改。如果您的GIF有n幀,則在on_texture方法的第(n + 1)次調用後停止動畫。

from kivy.app import App 
from kivy.uix.image import Image 

class MyImage(Image): 
    frame_counter = 0 
    frame_number = 2 # my example GIF had 2 frames 

    def on_texture(self, instance, value):  
     if self.frame_counter == self.frame_number + 1: 
      self._coreimage.anim_reset(False) 
     self.frame_counter += 1 


class MyApp(App): 
    def build(self): 
     return MyImage(source = "test.gif") 

if __name__ == '__main__': 
    MyApp().run() 
+0

非常感謝,你不能imagen你有多少幫助我 – Gilgamesch

+0

@Gilgamesch,我想我可以幫助你越早,如果你有回答這個評論:http://stackoverflow.com/questions/30726524/run-an- GIF動畫,一次-ON-kivy僅#comment49537709_30727495 – Nykakin