Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ui.py
from scene import *
import ui, random, scene
class MyScene (Scene):
def setup(self):
self.Pos = [50, 50]
def draw(self):
background(0, 0, 0)
self.Pos[0] += random.randint(-2, 2)
self.Pos[1] += random.randint(-2, 2)
fill(1, 1, 1)
ellipse(self.Pos[0], self.Pos[1], 2, 2)
text('If this isn\'t moving,\nthen the Scene is paused.', 'Arial', 12, self.Pos[0]+2, self.Pos[1]+2, 9)
text('Tap here to open another UI view.\nDrag down with 2 fingers to close.', 'Arial', 16, 0, 0, 9)
def touch_began(self, touch):
if touch.location.y < 50:
ui.View().present()
else:
self.Pos = [touch.location.x, touch.location.y]
class SceneViewer(ui.View):
def __init__(self, in_scene):
self.present('full_screen', hide_title_bar = True)
scene_view = scene.SceneView(frame=self.frame)
scene_view.scene = in_scene
self.add_subview(scene_view)
SceneViewer(MyScene())
@cclauss

This comment has been minimized.

Copy link

@cclauss cclauss commented Nov 7, 2014

import ui, random, scene

g_scene_id = 0

class MyScene (scene.Scene):
    def __init__(self, parent):
        global g_scene_id
        self.parent = parent
        self.msg = 'Scene {}: '.format(g_scene_id)
        g_scene_id += 1
        self.Pos = [50, 50]

    def draw(self):
        scene.background(0, 0, 0)

        self.Pos[0] += random.randint(-2, 2)
        self.Pos[1] += random.randint(-2, 2)

        scene.fill(1, 1, 1)
        scene.ellipse(self.Pos[0], self.Pos[1], 2, 2)

        msg = self.msg + "If this isn't moving,\nthen the Scene is paused."
        scene.text(msg, 'Arial', 12, self.Pos[0]+2, self.Pos[1]+2, 9)

        msg = 'Tap here to open another UI view.\nDrag down with 2 fingers to close.'
        scene.text(msg, 'Arial', 16, 0, 0, 9)

    def touch_began(self, touch):
        if touch.location.y < 50:
            self.parent.set_scene()
        else:
            self.Pos = touch.location

class SceneViewer(ui.View):
    def __init__(self):
        self.present('full_screen', hide_title_bar = True)
        self.scene_view = scene.SceneView(frame=self.frame)
        self.set_scene()
        self.add_subview(self.scene_view)

    @ui.in_background
    def set_scene(self):
        self.scene_view.scene = MyScene(self)

SceneViewer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.