使用Python中pyglet,为什么我的帧速率,如果我的鼠标拖动加快? [英] Using pyglet in python, why does my frame rate speed up if I mouse-drag?

查看:1327
本文介绍了使用Python中pyglet,为什么我的帧速率,如果我的鼠标拖动加快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了使用Python的pyglet包一个简单的图像显示。在我的的Linux笔记本电脑中,code的工作我如何预计,每秒显示一个恒定的60帧。

I wrote a simple image display using python's pyglet package. On my Linux laptop, the code worked how I expected, displaying a constant 60 frames per second.

在我的Windows 7桌面(从合理的新 @Xi 用的GeForce GTX 550 Ti)的,但是,帧速率是非常非常低(〜10 FPS或更小)。我不认为这是一个硬件限制,不过,由于鼠标拖动事件加速帧速率提升显着(60 FPS以上)。

On my Windows 7 desktop (reasonably new from @Xi with a GeForce GTX 550 Ti), however, the frame rate is very very low (~10 FPS or less). I don't think this is a hardware limitation, however, because mouse-drag events speed the frame rate up drastically (60 FPS or more).

为什么我的帧频在Windows上这么低的时候我不是鼠标拖动,和这么快的时候我是谁?

下面是简化code我用它来产生这种行为:

Here's the simplified code I use to produce this behavior:

import pyglet
from pyglet.window import mouse

image_1 = pyglet.resource.image('1.png')
image_2 = pyglet.resource.image('2.png')

fps_display = pyglet.clock.ClockDisplay()
image_x, image_y = 0, 0
frame = 0

window = pyglet.window.Window(image_1.width, image_2.height)

@window.event
def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
    global image_x, image_y
    if buttons == mouse.LEFT:
        image_x += dx
        image_y += dy

@window.event
def on_draw():
    global frame
    frame += 1
    window.clear()
    if frame%2 == 0:
        image = image_1
    else:
        image = image_2
    image.blit(x=image_x, y=image_y,
               height=image.height,
               width=image.width)
    fps_display.draw()

if __name__ == '__main__':
    pyglet.app.run()

1.png和2.png具有相同的像素尺寸,他们只是不同的图像,这样我就可以看到帧翻转。我使用python 2.7.2和pyglet版本1.2dev。我很高兴地补充一点,将是有益的任何其他信息。

'1.png' and '2.png' have the same pixel dimensions, they're just different images so I can see the frame flipping. I'm using python 2.7.2 and pyglet version 1.2dev. I'm happy to add any additional information that would be helpful.

推荐答案

去过一段时间,因为我做任何pyglet,但一些老code回头看,我看到这一切似乎使用pyglet时钟设置为

Been a while since I did any pyglet, but looking back at some old code, I see it all seems to use a pyglet clock setup with

 clock.schedule_interval(self.update,1.0/75.0)   
 clock.set_fps_limit(75)

在一个子类pyglet窗口取更新速率控制(其中更新是由时间步长参数推进游戏世界的窗口方法,以及在无效窗口)。我不认为在pyglet其中任何保证特别有规律股票的更新速度,否则。

in a subclassed pyglet Window to take control of the update rate (where update is a window method which advances the game world by a timestep parameter, and invalidates the window). I don't think there is anything in pyglet which particularly guarantees a regular "ticker" update rate otherwise.

这篇关于使用Python中pyglet,为什么我的帧速率,如果我的鼠标拖动加快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆