python - Pygame, trying to erase sprite -
i making pygame app
with app, can place blue dot around screen mouse right click.
middle mouse supposed erase dot, feature isn't working....
# -*- coding: utf-8 -*- import pygame pygame.locals import * def func_circle(x,y): cercle=pygame.sprite.sprite() pygame.sprite.sprite.__init__(cercle) cercle.image=pygame.surface((500,500)) cercle.image.fill((0,0,0)) cercle.image.set_colorkey((0,0,0)) pygame.draw.circle(cercle.image,(0,0,255),(cercle.image.get_rect().centerx,cercle.image.get_rect().centery),25,0) cercle.image.convert_alpha() cercle.rect=cercle.image.get_rect() cercle.rect.centerx=x cercle.rect.centery=y return cercle pygame.init() fenetre = pygame.display.set_mode((640, 480)) background = pygame.surface(fenetre.get_size()) background = background.convert() background.fill((250, 250, 250)) liste_des_sprites = pygame.sprite.layeredupdates() continuer = 1 while continuer: event in pygame.event.get(): if event.type==mousebuttondown , event.button==3: my_cicle=func_circle( event.pos[0],event.pos[1]) liste_des_sprites.add(my_cicle) if event.type==mousebuttondown , event.button==2: print "trying erase blue dot" my_cicle.kill() liste_des_sprites.empty() if event.type==quit: continuer=0 liste_des_sprites.draw(fenetre) pygame.display.update()
you have clear screen - example fill black color
fenetre.fill( (0,0,0) ) # clear screen liste_des_sprites.draw(fenetre) # draw circles again pygame.display.update() # send screen on monitor
or draw background remove old elements.
fenetre.blit( background, (0,0) ) # blit background clear screen liste_des_sprites.draw(fenetre) # draw circles again pygame.display.update() # send screen on monitor
Comments
Post a Comment