Bonjour, je commence à créer un petit jeu en python avec pygame, mais je rencontre un problème avec la détection des clicks de souris.
Je voudrais que quand l'image de l'ordinateur est cliquée, une autre image apparaisse, mais le click n'est pas détecté (en tout cas pas à chaque fois, environ une fois sur 3).
Mon code :
#commandBoard
import pygame
from pygame.locals import *
from variables import *
SCREEN = False
applis = [
[googlE, 20, 20],
]
def Screen(pressedKey):
print(2)
global SCREEN
pygame.draw.rect(screen, (0, 0, 0), (0, 0, infos.current_w, infos.current_h))
pygame.draw.rect(screen, (0, 0, 200), (infos.current_w-35, infos.current_h-5, 10, 5))
pygame.draw.rect(screen, (50, 50, 50), (10, 10, infos.current_w-20, infos.current_h-60))
#applis
for i in range(len(applis)):
rectA = applis[i][0].get_rect()
rectA.x, rectA.y = applis[i][1], applis[i][2]
screen.blit(applis[i][0], (rectA))
if pressedKey[K_ESCAPE]:
SCREEN = False
showCommandBoard = False
class CommandBoard:
def __init__(self, x, y):
self.x = x
self.y = y
self.w = 600
self.h = 300
def events(self, pressedKey, playerRect, player, mouseRect):
global showCommandBoard, SCREEN
pygame.draw.rect(screen, (50, 50, 50), (self.x, self.y, self.w, self.h))
rect = pygame.Rect(self.x, self.y, self.w, self.h)
if playerRect.colliderect(rect) and pressedKey[K_RETURN]:
showCommandBoard = setShowCommandBoard(True)
if showCommandBoard:
screen.blit(desktoP, (0, 0))
#ecran
screeNRect = screeN.get_rect()
screeNRect.x, screeNRect.y = 400, infos.current_h - 650
if mouseRect.colliderect(screeNRect):
screen.blit(screeN2, (screeNRect))
else:
screen.blit(screeN, (screeNRect))
screen.blit(arial2.render("[x]", True, (255, 255, 255)), (0, 0))
for event in pygame.event.get():
if event.type==MOUSEBUTTONUP and event.button==1:
if mouseRect.colliderect(screeNRect):
SCREEN=True
print(1)
player.canMove=False
player.show=False
if SCREEN:
Screen(pressedKey)
if pressedKey[K_x]:
showCommandBoard = setShowCommandBoard(False)
player.canMove=True
player.show=True
il doit manquer du code pour le faire fonctionner (plein de choses non définis dans le code montré, pas de code qui lance le jeu, ... et incompréhension de la logique)
tout ce que je peux dire c'est que tu consumes tous les événements pygame entre les lignes 64 et 68
Problème clicks pygame
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
Python c'est bon, mangez-en.