Combine Scene and Ui module
Does anyone know how I can combine a user interface using the Ui module and a game from the scene module? When editing the .pyui file there is the option of adding a custom view, but I don't know how to display a scene game in it
In your pyui file (example.pyui here), add a custom view, and set its "Custom View Class" field to
SceneView. Also set the name to something unique (I've used "sceneview" in the code below), so you can get a reference to the view more easily, after loading the UI. Load the UI, and set the
sceneattribute of the custom view. That's pretty much it.
from scene import * import ui class MyScene (Scene): def setup(self): pass # Define your scene like usual... v = ui.load_view('example.pyui') v['sceneview'].scene = MyScene() v.present('fullscreen')
#!python3 # _*_ coding:utf-8 _*_ from scene import * import ui class MyScene(Scene): def setup(self): self.background_color = 'midnightblue' self.ship = SpriteNode('spc:PlayerShip1Orange') self.ship.position = self.size / 2 self.add_child(self.ship) v = ui.load_view('UI_with_scene.pyui') v['sceneview'].scene = MyScene() v.present('sheet') # how to run MyScene in the sceneview ? !!! set its "Custom View Class" field to SceneView
Great, and you both :)