簡述
根據官方解釋:
Transition class that uses a Shader for animating the transition between 2 screens. By default, this class doesn’t assign any fragment/vertex shader.
意思是ShaderTransition是兩個Screen之間設置轉換動畫的類
基本範例
在main.py中寫上此段程式碼:
from kivy.app import App from kivy.uix.screenmanager import ScreenManager, Screen, ShaderTransition from kivy.properties import ObjectProperty class AScreen(Screen): pass class BScreen(Screen): pass class sm(ScreenManager): a1 = ObjectProperty(ShaderTransition(duration=3)) class MyApp(App): def build(self): return sm() if __name__ == '__main__': MyApp().run()
在my.kv中寫上此段程式碼:
<AScreen>: name: 'menu' BoxLayout: Button: text: 'Goto settings' on_press: root.manager.current = 'settings' Label: text: str(root.transition_progress) <BScreen>: name: 'settings' BoxLayout: Label: text: str(root.transition_progress) Button: text: 'still settings' on_press: root.manager.current = 'menu' <sm>: transition: root.a1 AScreen: BScreen:
執行結果如下:
由以上結果可以發現兩個Screen的轉換動畫為一片空白,因為我們並沒有指定轉換動畫為何。若想要有轉換動畫,可以用之前介紹的現成的Transition,或者研究fragment shaders語法並添加至ShaderTransition的fs參數(請容我跳過講解fragment shaders的概念與語法,這是另外一門程式語言)。
沒有留言:
張貼留言