I want to remove an image but i don't know really how to do it. I think we have to create a function ?
import pygame
pygame.init()
pygame.display.set_caption("Képomon")
screen = pygame.display.set_mode((284*2,472*2))
BattleStartImage = pygame.image.load('assets/BattleStart.png')
buttonRondAImage = pygame.image.load('assets/buttonRondA.png')
class Button():
def __init__(self, x, y, image, scale):
width = image.get_width()
height = image.get_height()
self.image = pygame.transform.scale(image, (int(width * scale), int(height * scale)))
self.rect = self.image.get_rect()
self.rect.topleft = (x,y)
self.clicked = False
def draw(self):
action = False
#get mouse position
pos = pygame.mouse.get_pos()
#check mouseover and clicked conditions
if self.rect.collidepoint(pos):
if pygame.mouse.get_pressed()[0]==1 and self.clicked == False:
self.clicked = True
action = True
if pygame.mouse.get_pressed()[0] == 0:
self.clicked = False
#draw button on screen
screen.blit(self.image,(self.rect.x, self.rect.y))
return action
buttonRondA = Button(427,572,buttonRondAImage,1)
running = True
while running:
screen.blit(BattleStartImage,(161,168))
# if buttonRondA.draw() == True:
# if screen.blit(BattleStartImage) == True :
# screen.delete(BattleStartImage)
# doesn't work
pygame.display.flip()
for event in pygame.event.get():
if event.type==pygame.QUIT:
running=False
pygame.quit()
print("Fermeture du jeu")
I don't know what is the solution, but screen.delete , buttonRondA.draw() == True and screen.blit(BattleStartImage) doesn't work
source https://stackoverflow.com/questions/77512069/how-to-remove-an-image-with-pygame
Comments
Post a Comment