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


Python clock.tick函数代码示例

本文整理汇总了Python中pyglet.clock.tick函数的典型用法代码示例。如果您正苦于以下问题:Python tick函数的具体用法?Python tick怎么用?Python tick使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_limit_fps

    def test_limit_fps(self):
        """
        Test that the clock effectively limits the
        frames per second to 60 Hz when set to.

        Because the fps are bounded, we expect a small error (1%)
        from the expected value.
        """
        ticks = 20
        fps_limit = 60
        expected_delta_time = ticks*1./fps_limit

        clock.set_fps_limit(fps_limit)

        t1 = time.time()
        # Initializes the timer state.
        clock.tick()
        for i in range(ticks):
            clock.tick()
        t2 = time.time()

        computed_time_delta = t2 - t1

        self.assertAlmostEqual(computed_time_delta,
                               expected_delta_time,
                               delta=0.01*expected_delta_time)
开发者ID:DiscoBizzle,项目名称:Ghost-Simulator,代码行数:26,代码来源:FPS.py

示例2: test_sprite

    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball1 = BouncySprite(0, 0, 64, 64, image, properties=dict(dx=10, dy=5))
        ball2 = BouncySprite(288, 0, 64, 64, image, properties=dict(dx=-10, dy=5))
        view = FlatView(0, 0, 320, 320, sprites=[ball1, ball2])
        view.fx, view.fy = 160, 160

        clock.set_fps_limit(60)
        e = TintEffect((0.5, 1, 0.5, 1))
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            ball1.update()
            ball2.update()
            if ball1.overlaps(ball2):
                if "overlap" not in ball2.properties:
                    ball2.properties["overlap"] = e
                    ball2.add_effect(e)
            elif "overlap" in ball2.properties:
                ball2.remove_effect(e)
                del ball2.properties["overlap"]

            view.clear()
            view.draw()
            w.flip()

        w.close()
开发者ID:odyaka341,项目名称:pyglet,代码行数:30,代码来源:SPRITE_OVERLAP.py

示例3: on_draw

    def on_draw(self):
        self.clear()

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        (w, h) = self.get_size()
        gl.glScalef(
            float(min(w, h))/w,
            -float(min(w, h))/h,
            1
        )

        gl.gluPerspective(45.0, 1, 0.1, 1000.0)
        gl.gluLookAt(0, 0, 2.4,
                     0, 0, 0,
                     0, 1, 0)

        global render_texture
        render_texture = self.texture

        for v in self.visions.values():
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            v.iteration()

        buf = pyglet.image.get_buffer_manager().get_color_buffer()
        rawimage = buf.get_image_data()
        self.texture = rawimage.get_texture()

        clock.tick()
开发者ID:ff-,项目名称:pineal,代码行数:30,代码来源:windows.py

示例4: instructionScreen

def instructionScreen(windowSurface, WWIDTH, FRAMES, background_image, background_position):

    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        windowSurface.blit(background_image, background_position)
        
        displayText(windowSurface, 128, WWIDTH / 2, 125, 'MEGA', RED)
        displayText(windowSurface, 128, WWIDTH / 2, 275, 'JUMP!', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 400, 'Space to jump (+ down arrow for small jump, M for MegaJump)', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 450, 'Left & Right arrows to move (+ up arrow to move faster)', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 500, 'Q to quit, R to reset', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 550, 'Only 1 MegaJump per game!', RED)
        displayText(windowSurface, 20, WWIDTH / 2, 600, 'Press ESC to return to main screen', GREEN)

        pygame.draw.circle(windowSurface, GOLD, (510, 550), 10, 0)

        if pygame.key.get_pressed()[K_ESCAPE]:
            return

        pygame.display.flip()

        clock.set_fps_limit(FRAMES)
        clock.tick()
开发者ID:axemaster1974,项目名称:MegaJump2,代码行数:28,代码来源:gameFunc.py

示例5: wait

def wait(ms):
	a = clock.get_fps()
	ct = 0
	loopcount = (ms / 1000.0) * a
	while ct < loopcount:
		clock.tick()
		ct+=1
开发者ID:alicen6,项目名称:brain_assessor,代码行数:7,代码来源:motion.py

示例6: test_sprite

    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball = Sprite(0, 0, 64, 64, image)
        view = FlatView(0, 0, 320, 320, sprites=[ball])

        w.push_handlers(view.camera)

        dx, dy = (10, 5)

        clock.set_fps_limit(30)
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            # move, check bounds
            ball.x += dx; ball.y += dy
            if ball.left < 0: ball.left = 0; dx = -dx
            elif ball.right > w.width: ball.right = w.width; dx = -dx
            if ball.bottom < 0: ball.bottom = 0; dy = -dy
            elif ball.top > w.height: ball.top = w.height; dy = -dy

            # keep our focus in the middle of the window
            view.fx = w.width/2
            view.fy = w.height/2

            view.clear()
            view.draw()
            w.flip()

        w.close()
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:32,代码来源:FLAT_SPRITE.py

示例7: run

    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()
开发者ID:tartley,项目名称:sole-scion,代码行数:26,代码来源:gameloop.py

示例8: test_fps

 def test_fps(self):
     clock.set_default(clock.Clock())
     self.assertTrue(clock.get_fps() == 0)
     for i in range(10):
         time.sleep(0.2)
         clock.tick()
     result = clock.get_fps()
     self.assertTrue(abs(result - 5.0) < 0.05)
开发者ID:njoubert,项目名称:UndergraduateProjects,代码行数:8,代码来源:FPS.py

示例9: main_loop

 def main_loop(self):
     clock.set_fps_limit(self.update_fps)
     while not self.has_exit:
         self.dispatch_events()
         self.update_cells()
         self.draw_grid()
         clock.tick()
         self.flip()
开发者ID:reuteran,项目名称:game-of-life,代码行数:8,代码来源:grid.py

示例10: on_draw

 def on_draw(self):
     self.clear() # clearing buffer
     clock.tick() # ticking the clock
     
     # showing FPS
     self.fpstext.text = "fps: %d" % clock.get_fps()
     self.fpstext.draw()
                
     # flipping
     self.flip()
开发者ID:guillermoaguilar,项目名称:pyglet_tutorial,代码行数:10,代码来源:game1.py

示例11: test_tick

 def test_tick(self):
     clock.set_default(clock.Clock())
     result = clock.tick()
     self.assertTrue(result == 0)
     time.sleep(1)
     result_1 = clock.tick()
     time.sleep(1)
     result_2 = clock.tick()
     self.assertTrue(abs(result_1 - 1.0) < 0.05)
     self.assertTrue(abs(result_2 - 1.0) < 0.05)
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:10,代码来源:TICK.py

示例12: test_schedule_multiple

    def test_schedule_multiple(self):
        clock.set_default(clock.Clock())
        clock.schedule(self.callback)
        clock.schedule(self.callback)
        self.callback_count = 0

        clock.tick()
        self.assertTrue(self.callback_count == 2)

        clock.tick()
        self.assertTrue(self.callback_count == 4)
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:11,代码来源:SCHEDULE.py

示例13: test_fps_limit

    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick() # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:11,代码来源:FPS_LIMIT.py

示例14: main

def main():
    global target, step
    while not w.has_exit:
        clock.tick()
        w.clear()
        
        target.pos.x += step
        if abs(target.pos.x) >= 17:
            step *= -1
        w.dispatch_events()
        context.render()
        w.flip()
开发者ID:Knio,项目名称:miru,代码行数:12,代码来源:track00.py

示例15: test_unschedule

    def test_unschedule(self):
        clock.set_default(clock.Clock())
        clock.schedule(self.callback)

        result = clock.tick()
        self.assertTrue(result == self.callback_dt)
        self.callback_dt = None
        time.sleep(1)
        clock.unschedule(self.callback)

        result = clock.tick()
        self.assertTrue(self.callback_dt == None)
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:12,代码来源:SCHEDULE.py


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