Answer the question
In order to leave comments, you need to log in
How to change the size or color of an image when clicking on an image in Pygame?
when you click on the screen, the size of the image changes, but I need it to change when you click on the image itself and not on any part of the screen
if event.type == pygame.MOUSEBUTTONDOWN:
my_image = pygame.transform.scale(my_image, (IMG_SIZE - 100, IMG_SIZE - 100))
thanks for the answer
Answer the question
In order to leave comments, you need to log in
1) Place your code in a tag <code></code>
2) Use the collidepoint method of the Rect class :
...
if event.type == pygame.MOUSEBUTTONDOWN:
# Получаем координаты курсора
pos = pygame.mouse.get_pos()
# Получаем прямоугольник
rect = my_image.get_rect()
# Проверяем попадание точки в прямоугольник
if rect.collidepoint(pos):
# Если точка попала - изменяете размер картинки
change_image_size()
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question