当前位置: 首页>>代码示例>>Python>>正文


Python Window.set_visible方法代码示例

本文整理汇总了Python中pyglet.window.Window.set_visible方法的典型用法代码示例。如果您正苦于以下问题:Python Window.set_visible方法的具体用法?Python Window.set_visible怎么用?Python Window.set_visible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.window.Window的用法示例。


在下文中一共展示了Window.set_visible方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
def main():
    # Create the main window
    window = Window(800, 600, visible=False,
                   caption="FF:Tactics.py", style='dialog')
    # Create the default camera and have it always updating
    camera = Camera((-600, -300, 1400, 600), (400, 300), 300, speed=PEPPY)
    clock.schedule(camera.update)

    # Load the first scene
    world = World(window, camera)
    world.transition(MainMenuScene)

    # centre the window on whichever screen it is currently on
    window.set_location(window.screen.width/2 - window.width/2,
                        window.screen.height/2 - window.height/2)
    # clear and flip the window
    # otherwise we see junk in the buffer before the first frame
    window.clear()
    window.flip()

    # make the window visible at last
    window.set_visible(True)

    # finally, run the application
    pyglet.app.run()
开发者ID:johnmendel,项目名称:python-tactics,代码行数:27,代码来源:tactics.py

示例2: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
class Gameloop(object):

    def __init__(self):
        self.window = None

    def init(self):
        self.world = World()
        self.world.init()
        populate(self.world)

        bitmaps = Bitmaps()
        bitmaps.load()
        self.render = Render(bitmaps)
        self.camera = Camera(zoom=10.0)

        self.window = Window(fullscreen=False, visible=False)
        self.window.set_exclusive_mouse(True)
        self.window.on_draw = self.draw
        self.window.on_resize = self.render.resize

        self.controls = Controls(self.world.bat)
        self.window.set_handlers(self.controls)

        self.render.init()
        clock.schedule(self.update)
        self.hud_fps = clock.ClockDisplay()

        self.window.set_visible()


    def update(self, dt):
        # scale dt such that the 'standard' framerate of 60fps gives dt=1.0
        dt *= 60.0
        # don't attempt to compensate for framerate of less than 30fps. This
        # guards against huge explosion when game is paused for any reason
        # and then restarted
        dt = min(dt, 2)
        self.controls.update()
        self.world.update()
        self.window.invalid = True

    def draw(self):
        self.window.clear()
        self.camera.world_projection(self.window.width, self.window.height)
        self.camera.look_at()
        self.render.draw(self.world)

        self.hud_fps.draw()

        return EVENT_HANDLED

    def stop(self):
        if self.window:
            self.window.close()
开发者ID:tartley,项目名称:pyong,代码行数:56,代码来源:gameloop.py

示例3: Application

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
class Application(object):

    def __init__(self):
        self.win = None
        self.music = None
        self.vsync = (
            not settings.has_option('all', 'vsync') or
            settings.getboolean('all', 'vsync')
        )


    def launch(self):
        self.win = Window(
            width=1024, height=768,
            vsync=self.vsync,
            visible=False)
        self.win.set_mouse_visible(False)
        GameItem.win = self.win

        load_sounds()

        self.music = Music()
        self.music.load()
        self.music.play()

        keystate = key.KeyStateHandler()
        self.win.push_handlers(keystate)

        game = Game(keystate, self.win.width, self.win.height)

        handlers = {
            key.M: self.toggle_music,
            key.F4: self.toggle_vsync,
            key.ESCAPE: self.exit,
        }
        game.add(KeyHandler(handlers))

        render = Render(game)
        render.init(self.win)
        game.startup(self.win)
        self.win.set_visible()
        pyglet.app.run()


    def toggle_vsync(self):
        self.vsync = not self.vsync
        self.win.set_vsync(self.vsync)

    def toggle_music(self):
        self.music.toggle()

    def exit(self):
        self.win.has_exit = True
开发者ID:mjs,项目名称:brokenspell,代码行数:55,代码来源:application.py

示例4: main

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
def main():
    win = Window(fullscreen=True, visible=False)
    camera = Camera(win.width, win.height, (0, 0), 100)
    renderer = Renderer()
    maze = Maze()
    maze.create(50, 30, 300)
    keyboard = Keyboard()
    keyboard.key_handlers[key.ESCAPE] = win.close
    keyboard.key_handlers.update(camera.key_handlers)
    clock.schedule(maze.update)
    win.on_draw = lambda: renderer.on_draw(maze, camera, win.width, win.height)
    win.on_key_press = keyboard.on_key_press
    keyboard.print_handlers()
    win.set_visible()
    app.run()
开发者ID:msarch,项目名称:py,代码行数:17,代码来源:run.py

示例5: PygletApp

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
class PygletApp(object):

    def __init__(self):
        self.window = Window(visible=False, fullscreen=False)
        self.window.on_resize = self.on_resize
        self.window.on_draw = self.on_draw
        self.window.on_key_press = self.on_key_press

        self.files = SvgFiles()

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(
            0.0, -0.0, 1.0,  # eye
            0.0, -0.0, -1.0, # lookAt
            0.0, 1.0, 0.0)  # up


    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT)
        self.files.draw()
        return EVENT_HANDLED


    def on_resize(self, width, height):
        # scale is distance from screen centre to top or bottom, in world coords
        scale = 110
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        aspect = width / height
        gluOrtho2D(
            -scale * aspect,
            +scale * aspect,
            -scale,
            +scale)
        return EVENT_HANDLED


    def on_key_press(self, symbol, modifiers):
        if symbol == key.ESCAPE:
            self.window.close()
            return
        self.files.next()


    def run(self):
        self.window.set_visible()
        app.run()
开发者ID:msarch,项目名称:py,代码行数:50,代码来源:demo.py

示例6: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
class Gameloop(object):

    def __init__(self, options):
        self.options = options
        self.window = None
        self.fpss = []
        self.time = 0.0
        self.level = None


    def prepare(self, options):
        self.window = Window(
            fullscreen=options.fullscreen,
            vsync=options.vsync,
            visible=False,
            resizable=True)
        self.window.on_draw = self.draw_window

        self.world = World()
        self.player = Player(self.world)
        self.camera = GameItem(
            position=origin,
            update=CameraMan(self.player, (3, 2, 0)),
        )
        self.level_loader = Level(self)
        success = self.start_level(1)
        if not success:
            logging.error("ERROR, can't load level 1")
            sys.exit(1)

        self.update(1/60)

        self.window.push_handlers(KeyHandler(self.player))

        self.render = Render(self.world, self.window, self.camera)
        self.render.init()

        self.music = Music()
        self.music.load()
        self.music.play()


    def run(self):
        pyglet.clock.schedule(self.update)
        self.window.set_visible()
        self.window.invalid = False
        pyglet.app.run()


    def update(self, dt):
        if self.options.print_fps:
            self.fpss.append(1/max(1e-6, dt))
        dt = min(dt, 1 / 30)
        self.time += dt

        for item in self.world:
            if hasattr(item, 'update'):
                item.update(item, dt, self.time)

        if self.player_at_exit():
            self.world.remove(self.player)
            pyglet.clock.schedule_once(
                lambda *_: self.start_level(self.level + 1),
                1.0
            )

        self.window.invalid = True


    def start_level(self, n):
        success = self.level_loader.load(self.world, n)
        if not success:
            logging.info('No level %d' % (n,))
            self.stop()
            return False
               
        self.level = n
        pyglet.clock.schedule_once(
            lambda *_: self.world.add(self.player),
            2.0,
        )
        return True


    def player_at_exit(self):
        items = self.world.collision.get_items(self.player.position)
        if any(hasattr(item, 'exit') for item in items):
            dist2_to_exit = dist2_from_int_ords(self.player.position)
            if dist2_to_exit < EPSILON2:
                return True
        return False


    def draw_window(self):
        self.window.clear()
        self.render.draw_world()
        if self.options.display_fps:
            self.render.draw_hud()
        self.window.invalid = False
        return EVENT_HANDLED
#.........这里部分代码省略.........
开发者ID:mjs,项目名称:pyweek11-cube,代码行数:103,代码来源:gameloop.py

示例7: make_army

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
def make_army(size, menagerie):
    army = []
    for col in range(size):
        for row in range(size):
            creature_type = menagerie[randint(0, len(menagerie)-1)]
            x = (col+0.5)*16 - size * 8
            y = (row+0.5)*16 - size * 8
            creature = Creature(creature_type, (x, y))
            creature.da = uniform(-0.1, +0.1)
            creature.velocity = uniform(0, +0.5)
            army.append(creature)
    return army

creatures = make_army(12, [blue_ghost, orange_ghost, pacman, pink_ghost, red_ghost])

def update(dt):
    for creature in creatures:
        creature.update(dt)

clock.schedule(update)

key_handlers[key.ESCAPE] = win.close
win.on_draw = lambda: renderer.on_draw(creatures, camera, win.width, win.height)
win.on_key_press = on_key_press

print "keys to try:", [symbol_string(k) for k in key_handlers.keys()]
stdout.flush()
win.set_visible()
app.run()

开发者ID:msarch,项目名称:py,代码行数:31,代码来源:run.py

示例8: print_style

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
def print_style(style, indent=''):
    import textwrap
    print '\n'.join(textwrap.wrap(repr(style), initial_indent=indent,
            subsequent_indent=indent))
    if style.parent:
        print_style(style.parent, '  ' + indent)

def print_element(element, indent=''):
    import textwrap
    print '\n'.join(textwrap.wrap(repr(element), initial_indent=indent,
            subsequent_indent=indent))
    if element.style_context:
        print_style(element.style_context, indent + '  ')
    for child in element.children:
        print_element(child, '  ' + indent)

glClearColor(1, 1, 1, 1)

window.set_visible()

while not window.has_exit:
    clock.tick()
    print 'FPS = %.2f\r' % clock.get_fps(),

    window.dispatch_events()
    glClear(GL_COLOR_BUFFER_BIT)
    layout.draw()

    window.flip()
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:31,代码来源:xhtml.py

示例9: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import set_visible [as 别名]
class Gameloop(object):

    instance = None

    def __init__(self):
        Gameloop.instance = self
        self.window = None
        self.camera = None
        self.world = None
        self.renderer = None
        self.paused = False
        self.fps_display = None
        Keyboard.handlers.update({
            key.PAGEUP: lambda: self.camera.zoom(2.0),
            key.PAGEDOWN: lambda: self.camera.zoom(0.5),
            key.ESCAPE: self.quit_game,
            key.PAUSE: self.toggle_pause,
            key.F12: lambda: save_screenshot(self.window),
        })


    def init(self, name, version):
        clock.set_fps_limit(FPS_LIMIT)
        self.fps_display = clock.ClockDisplay()

        self.camera = Camera((0, 0), 800)
        self.renderer = Renderer(self.camera)
        caption = '%s v%s' % (name, version)
        self.window = Window(
            caption=caption, fullscreen=True, visible=False)
        self.window.on_key_press = on_key_press
        self.window.push_handlers(Keyboard.keystate)

        graphics = load_graphics()

        self.world = World()
        builder = LevelBuilder()
        seed(1)
        builder.build(self.world, 75, graphics)

        self.world.player = Player()
        self.world.player.add_to_space(self.world.space, (0, 200), 0)
        self.world.chunks.update(self.world.player.chunks)


    def dispose(self):
        if self.window:
            self.window.close()


    def run(self):
        try:
            self.window.set_visible()
            while not self.window.has_exit:
                self.window.dispatch_events()
                clock.tick()
                if self.world and not self.paused:
                    self.world.tick(1/FPS_LIMIT)
                if self.world and hasattr(self.world, 'player'):
                    player_position = self.world.player.chunks[0].body.position
                    self.camera.x, self.camera.y = player_position
                    self.camera.angle = atan2(
                        player_position.x,
                        player_position.y)

                self.camera.update()
                if self.renderer:
                    aspect = (
                        self.window.width / self.window.height)
                    self.renderer.draw(self.world, aspect)
                self.camera.hud_projection(
                    (self.window.width, self.window.height))
                self.fps_display.draw()
                self.window.flip()
        finally:
            self.dispose()


    def toggle_pause(self):
        self.paused = not self.paused


    def quit_game(self):
        self.window.has_exit = True
开发者ID:tartley,项目名称:sole-scion,代码行数:86,代码来源:gameloop.py


注:本文中的pyglet.window.Window.set_visible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。