I'm learning Pygame to make games w/ Python. However, I'm encountering a problem. I'm trying to detect when the player is currently clicking the screen, but my code isn't working. Is my code actually screwed, or is it just the online Pygame compiler that I'm using?
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 800))
while True:
pygame.display.update()
mouse = pygame.mouse.get_pressed()
if mouse:
print("You are clicking")
else:
print("You released")
When I ran this code, the output console spammed the text "You are clicking", thousands of times in a second. Even when I'm not clicking the screen, it still says this. Even when my mouse isn't over the screen. Just the same text. Over, and over. Is Pygame executing my program correctly?
To learn Pygame, I am using the official Docs from the developers. https://www.pygame.org/docs/ Is this an outdated way to learn, is this why my code continues to run errors?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…