import pygame
pygame.init()
def main():
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('game')
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(pygame.color.Color('yellow'))
box = pygame.Surface((100,100))
box = box.convert()
box.fill(pygame.color.Color('red'))
t = True
clock = pygame.time.Clock()
while t:
for event in pygame.event.get():
if event.type == pygame.QUIT:
t = False
elif event.type == pygame.MOUSEBUTTONDOWN:
posi = pygame.mouse.get_pos()
print 'mous down', posi
screen.blit(box,posi)
elif event.type == pygame.MOUSEBUTTONUP:
print 'mouse up', pygame.mouse.get_pos()
screen.blit(background, (0,0))
pygame.display.flip()
main()
I just start to learn pygame. I want to make a box when I click mouse in the background, but I don't see a box from this code. also in this statement : for event in pygame.event.get(): how many event will actually be taken every time in this for loop? This is where I got confused the most. Thank you in advance.