document.querySelectorAll(".mine").classList.remove("mine")
这是完整的代码,它是滚动程序的原型,它已被破坏(但是正在运行),但是,每当我尝试单击它时,我都会得到没有响应的窗口
答案 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()