Pygame窗口显示无响应消息

时间:2019-12-08 16:38:03

标签: python pygame

document.querySelectorAll(".mine").classList.remove("mine")

这是完整的代码,它是滚动程序的原型,它已被破坏(但是正在运行),但是,每当我尝试单击它时,我都会得到没有响应的窗口

1 个答案:

答案 0 :(得分:1)

scroll的方法camera是一个无限循环:

  
class camera:
   def __init__(self,rel_x,x):
       self.x = 0
       self.rel_x = self.x % bgWidth
       self.scrolling = True
   def scroll(self,x):
       while self.scrolling == True:
           self.x -= 1
   # [...]

请注意,self.scrolling停留在true,循环永远不会终止。

方法scroll在主应用程序循环中被调用,因此不必在scroll中实现循环。只需选择(if)而不是迭代(while):

class camera:
    # [...]

    def scroll(self,x):
        if self.scrolling == True:
            self.x -= 1

    # [...]

此外,您已经通过win.fill(0)清除了显示,以通过pygame.display.update()更新了显示。 self.rel_x也必须更新:

class camera:
    def __init__(self,rel_x,x):
        self.x = 0
        self.rel_x = self.x % bgWidth
        self.scrolling = True
    def scroll(self,x):
        if self.scrolling == True:
            self.x -= 1
            self.rel_x = self.x % bgWidth
    def draw(self,win):
        win.blit(bg,(self.rel_x-bgWidth,0))

camo = camera(0,0)

while run:
    clock.tick()
    events()
    camo.scroll(0)
    win.fill(0)
    camo.draw(win)
    pygame.display.update()