鼠标点击IS不被识别
我试图在单击时使黑色单元格变成白色单元格,反之亦然。我似乎无法解决的问题是,无论我使用什么功能,当我单击鼠标时,我的程序都无法识别。我已经尝试了谷歌上的几乎所有搜索结果和堆栈溢出上的答案,但没有任何反应。这就是我目前正在使用的。
def update(self, event_list):
for event in event_list:
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
self.alive = not self.alive
if self.alive:
self.image = self.alive_image
else:
self.dead_image
#main loop
while gen:
event_list = pygame.event.get()
for event in event_list:
if event.type == pygame.QUIT:
run = false
all_cells.update(event_list)
clock.tick(60)
pygame.quit()
我还尝试了所有常用的函数,例如 pygame.mouse.get_press() 和 self.rect.collidepoint()。我应该尝试什么?
I am trying to make a black cell become a white cell when clicked, and vise versa. The problem that I can't seem to solve is that no matter what function I use, my program doesn't recognize when I click my mouse. I've tried just about every search result on both google and answer on stack overflow, but nothing happens. This is what I am currently using.
def update(self, event_list):
for event in event_list:
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
self.alive = not self.alive
if self.alive:
self.image = self.alive_image
else:
self.dead_image
#main loop
while gen:
event_list = pygame.event.get()
for event in event_list:
if event.type == pygame.QUIT:
run = false
all_cells.update(event_list)
clock.tick(60)
pygame.quit()
I also tried all the usual functions like pygame.mouse.get_press() and self.rect.collidepoint(). What should I try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要用
AS
self.dead_image
代码替换您的代码什么都没做。
You'll need to replace your
With
As at
self.dead_image
the code isn't doing anything.