Reputation: 828
I am making a pygame app
With this app, I can place blue dot around the screen with mouse right click.
Middle mouse is supposed to erase all the dot, but this feature isn't working....
# -*- coding: utf-8 -*-
import pygame
from 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:
for event in pygame.event.get():
if event.type==MOUSEBUTTONDOWN and event.button==3:
my_cicle=func_circle( event.pos[0],event.pos[1])
liste_des_sprites.add(my_cicle)
if event.type==MOUSEBUTTONDOWN and event.button==2:
print "trying to erase the blue dot"
my_cicle.kill()
liste_des_sprites.empty()
if event.type==QUIT:
continuer=0
liste_des_sprites.draw(fenetre)
pygame.display.update()
Upvotes: 1
Views: 1283
Reputation: 143125
You have to clear screen - for example fill it with 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 your background to remove old elements.
fenetre.blit( background, (0,0) ) # blit background to clear screen
liste_des_sprites.draw(fenetre) # draw circles again
pygame.display.update() # send screen on monitor
Upvotes: 3