什么“不能超过屏幕对象”错误意味着什么?

时间:2013-07-08 17:06:41

标签: python pygame livewires

我正在制作一个计时器模板,用于我创建的游戏。这是我对计时器模块的代码(尚未将它放入类中)

import time
import math
import pygame
from livewires import games, color
timer = 0

games.init(screen_width = 640, screen_height = 480, fps = 50)

gamefont = pygame.font.Font(None, 30)
timertext = gamefont.render('Timer: ' +str(timer), 1, [255,0,0])
screen.blit(timertext, [scoreXpos,20])

最终,我将有一个实时计时器,这就是我使用render和blit方法的原因,但是现在,我只有一个名为timer set的静态变量等于0.当我运行这个程序时,我收到一条错误,上面写着“不能超过屏幕上的对象”。我真的很困惑因为我以前从未见过这个错误,并且肯定不知道这意味着什么,或者如何修复它。如果有人能帮我理解正在发生的事情,我会非常感激。此外,我从活动线中导入游戏和颜色的原因是稍后在代码中将其用于其他目的。

1 个答案:

答案 0 :(得分:0)

Screen livewires类引发了异常。

...
class Screen(object): 

    initialized = 0 

    def __init__ (self, width=640, height=480, fps=50): 
        # Bomb if you try this more than once
        if Screen.initialized: 
            raise GamesError("Cannot have more than on Screen object")

        Screen.initialized = 1
...

您没有显示整个代码,因此我猜您在某处创建了Screen类的第二个实例。

相关问题