• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python clock.tick函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: savedGameScreen

def savedGameScreen(savedGames, windowSurface, WWIDTH, WHEIGHT, FRAMES, background_image, background_position):        

    time.sleep(0.3)
    
    while True:

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

        windowSurface.blit(background_image, background_position)
        displayTextLJ(windowSurface, 36, 50, 50, 'Saved Games List', RED)
        displayTextLJ(windowSurface, 24, 50, 100, "Name", RED)
        displayTextLJ(windowSurface, 24, 200, 100, "Difficulty", RED)
        displayTextLJ(windowSurface, 24, 350, 100, "Platforms", RED)
        displayTextLJ(windowSurface, 24, 500, 100, "Record", RED)
        
        displayTextLJ(windowSurface, 20, 50, 550, 'Press number to select game or D plus number to delete game', RED)
        displayTextLJ(windowSurface, 20, 50, 600, 'Escape to return to previous screen', RED)
        
        count = 1
        for game in savedGames:
            displayTextLJ(windowSurface, 20, 50, 100 + (count * 30), str(count) + ". " + game['name'], GREEN)
            displayTextLJ(windowSurface, 20, 200, 100 + (count * 30), game['difficulty'], GREEN)
            displayTextLJ(windowSurface, 20, 350, 100 + (count * 30), game['pnumber'], GREEN)
            if game['difficulty'] == "INSANE":
                displayTextLJ(windowSurface, 20, 500, 100 + (count * 30), "Score: " + game['score'], GREEN)
            else:
                displayTime(windowSurface, int(game['record']), 500, 100 + (count * 30), GREEN, 20, "True")
            count += 1

        if not pygame.key.get_pressed()[ord('d')]:
            for i in range(len(savedGames)):
                if pygame.key.get_pressed()[ord(str(i+1))]:
                    return savedGames[i], i

        if pygame.key.get_pressed()[ord('d')]:
            for i in range(len(savedGames)):
                if pygame.key.get_pressed()[ord(str(i+1))]:
                     del savedGames[i]
                     saveGames(windowSurface, WWIDTH, WHEIGHT, None, savedGames, None, "Delete")
                     time.sleep(0.5)
                     break
                       
        if pygame.key.get_pressed()[K_ESCAPE]:
            return None, None

        pygame.display.flip()

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


示例17: main_loop

 def main_loop(self):
     clock.set_fps_limit(30)
     clock.schedule_interval(self.animate_bird, 0.01)
     
     while not self.has_exit:
         self.dispatch_events()
         self.clear()
     
         self.update()
         self.draw()
     
         #Tick the clock
         clock.tick()
         self.flip()
开发者ID:jseutter,项目名称:featherwars,代码行数:14,代码来源:fowl.py


示例18: 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()
     
     self.spaceship.draw()
     for alien in self.aliens:
         alien.draw()
     
     # flipping
     self.flip()
开发者ID:guillermoaguilar,项目名称:pyglet_tutorial,代码行数:14,代码来源:game4.py


示例19: mainLoop

    def mainLoop(self):
        while not self.win.has_exit:
            self.win.dispatch_events()

            self.world.tick()

            self.camera.worldProjection()
            self.world.draw()

            self.camera.hudProjection()
            self.hud.draw()

            clock.tick()
            self.win.flip()
开发者ID:bjmgeek,项目名称:babytux,代码行数:14,代码来源:tartley.py


示例20: run_test

 def run_test(self):
     clock.set_fps_limit(30)
     while not self.w.has_exit:
         clock.tick()
         self.w.dispatch_events()
         self.view.fx += (self.keyboard[key.RIGHT] - self.keyboard[key.LEFT]) * 5
         self.view.fy += (self.keyboard[key.UP] - self.keyboard[key.DOWN]) * 5
         if self.marker is not None:
             self.marker.x = self.view.fx
             self.marker.y = self.view.fy
         self.view.clear()
         self.view.draw()
         self.w.flip()
     self.w.close()
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:14,代码来源:render_base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python clock.unschedule函数代码示例发布时间:2022-05-25
下一篇:
Python clock.set_fps_limit函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap