-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonManager.py
More file actions
29 lines (22 loc) · 897 Bytes
/
ButtonManager.py
File metadata and controls
29 lines (22 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pygame
# spsro ButtonManager v1.0
# copyright songro studio_ 2020 - 2023
class Button(): # button
def __init__(self, x, y, image, btnScale):
width = image.get_width()
height = image.get_height()
self.image = pygame.transform.scale(image, (int(width * btnScale), int(height * btnScale)))
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
self.isClicked = False
def drawBtn(self, surface): # draw
action = False
mousePos = pygame.mouse.get_pos()
if self.rect.collidepoint(mousePos):
if pygame.mouse.get_pressed()[0] == 1 and self.isClicked == False:
self.isClicked = True
action = True
if pygame.mouse.get_pressed()[0] == 0:
self.isClicked = False
surface.blit(self.image, (self.rect.x, self.rect.y))
return action