Forum Archive

UI launching a scene

chriswilson

Hi all,

I have made a game (which I have posted about before) using the scene module.

I am trying to get a pyui file to launch the scene. After some trial and error I managed it like this:

import ui
from black_white import *
from time import sleep
from scene import run

@ui.in_background
def start(sender):
    run(Game(), show_fps=False)

v = ui.load_view()
v.present('sheet', hide_title_bar = True)

black_white is the name of the script running my scene Game.

I could only get it to work by running the scene 'inside' the UI. I had to import time.sleep and scene.runas my script needs them, which seems quite messy. When I try to close the UI view v at the end of the start function, everything closes!

Does anyone know of a better way to do this?

jbap

You might be able to use a SceneView. Maybe it's just me, but I couldn't understand your question clearly. So this might not be the answer. But oh well.

You can create a SceneView:

sv = ui.SceneView()

Add your scene as a parameter of "sv", then use

main_view.add_subview(sv)

in your function.
Your button calls the function, the just clear the main_view and call the line above.

brumm

Here you can find an example PhotoTextV2.
It's a ui.View with two scrollviews. One for buttons and another one for the scene.SceneView.

edit: Have you tried ui.delay instead of time.sleep?

chriswilson

@jbap @brumm
Thanks for your replies. I'm going to try to implement that.