Forum Archive

Animate UI switching to scene

techteej

Is there any way to display an animation of some sort or some way to eliminate the delay from UI Switching to scene?

Sebastian

Why don't you just use a scene.SceneView instead of switching between ui and scene?

techteej

How would I do that?

Sebastian

I was thinking something like this:


import ui, scene

class MyScene (scene.Scene):
    def setup(self):
        pass

    def draw(self):
        scene.background(0, 0, 0)
        for touch in self.touches.values():
            scene.ellipse(touch.location.x-50, touch.location.y-50, 100, 100)


w, h = ui.get_screen_size()
root_view = ui.View(frame=(0, 0, w, h), background_color='white')
scene_view = scene.SceneView()
scene_view.frame = (0, 0, w, h)
scene_view.scene = MyScene()

def button_tapped(sender):
    sender.hidden = True 
    root_view.add_subview(scene_view)

button = ui.Button(frame=(w*0.5-50, h*0.5-50, 100, 100))
button.action = button_tapped
button.image = ui.Image.named('ionicons-ios7-play-32')

root_view.add_subview(button)
root_view.present()
techteej

I got most of it working here, but I can't get a view to remove.

    root_view.remove_subview(SelectACharacterView()) # this does not work
ccc
while root_view.subviews:
    root_view.remove_subview(root_view.subviews[-1])
techteej

@ccc This keeps the character view up but removes the game view

Sebastian

@techteej Looks like you tried to remove a newly created SelectACharacterView (which isn't a subview of root_view).

You would usually store the view as a variable or something, and then call root_view.remove_subview(subview). But you could probably do something like this:


for subview in root_view.subviews:
    if isinstance(subview, SelectACharacterView):
        root_view.remove_subview(subview)

ccc

We solved this one with sender.superview.close().