好的,我正在用 Pyglet 制作一个小游戏/原型,我对事件感到困惑。游戏运行不佳,通过分析我知道这是因为on_draw()每秒被调用 60 次,因为pyglet.clock.schedule_interval(). 我不完全知道为什么on_draw()目前正在使用它可以使用的所有 CPU,如果知道的话会很高兴。通过更多的分析,我知道绘制 100 个 Sprite 也需要大量的 CPU,比我认为它应该占用的要多(我什至不知道它应该占用 CPU 还是只占用 GPU)。
on_draw()默认情况下会做什么,我可以避免任何无用的额外内容吗?schedule_interval()不触发on_draw()?一些代码:
screen = pyglet.window.Window(800, 600, vsync=False, caption="Project")
tileimage = pyglet.image.create(50, 50, pyglet.image.SolidColorImagePattern((0, 255, 0, 255)))
class tileclass(pyglet.sprite.Sprite):
def __init__(self, x, y):
pyglet.sprite.Sprite.__init__(self, tileimage)
self.x = x
self.y = y
self.rect = pygame.Rect(self.x - self.width / 2, self.y - self.height / 2, self.width, self.height)
self.image.anchor_x = self.width // 2
self.image.anchor_y = self.height …Run Code Online (Sandbox Code Playgroud)