本文整理汇总了Python中screen.Screen.build方法的典型用法代码示例。如果您正苦于以下问题:Python Screen.build方法的具体用法?Python Screen.build怎么用?Python Screen.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类screen.Screen
的用法示例。
在下文中一共展示了Screen.build方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainApp
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import build [as 别名]
class MainApp(App):
settings = ObjectProperty(Settings())
def build(self):
self.running = False
self._register_keyboard()
self.world = World()
self.world.build(self.settings)
self.screen = Screen(size_hint_x=2)
self.screen.build(self.settings, self.world)
sync_property(self.screen, 'size', self.settings, 'world_size')
self.root.add_widget(self.screen)
return self.root
def gameloop(self, dt):
if self.running:
self.world.update(dt)
self.screen.update(dt)
def on_start(self):
# start after 0.5sec
Clock.schedule_once(self._toggle_running, 1)
Clock.schedule_interval(self.gameloop, 1/60.)
def _toggle_running(self, *args):
self.running = not self.running
def _register_keyboard(self):
self._keyboard = Window.request_keyboard(self._keyboard_closed, self.root, 'text')
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
if (keycode[1] == 'spacebar'):
self._toggle_running()
return True