[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Fast Blit with mask



Thanks for the help!! I could not have done it without you!!
This is the answer. It is very fast compared to all my other tries.

    surfaceA=pygame.Surface((1024,768),0,screen)
    surfaceB=pygame.Surface((1024,768),0,screen)
    tmpImage=pygame.Surface((1024,768),0,screen)
    surfaceB.set_colorkey(0xffffff)#white is clear
    tmpImage.set_colorkey(0x000000)#black is clear
    for a in range(0,20000) :
         pygame.draw.line(surfaceA,Colors[randint(0,11)],/
         (randint(0,700),randint(0,700)),/
         (randint(0,700),randint(0,500)),1)
    #Main Loop
    while 1:
        #Handle Input Events
        for event in pygame.event.get() :
            if event.type == QUIT : return
            elif event.type == KEYDOWN and event.key == K_ESCAPE : return
        rect=pygame.draw.line(surfaceB,WHITE,(randint(0,700),randint(0,700)),/
            (randint(0,700),randint(0,700)),22)
	rect.inflate_ip(22*2, 22*2)
        tmpImage.blit(surfaceA, rect, rect)
	tmpImage.blit(surfaceB, rect, rect)
	rect=screen.blit(tmpImage, rect, rect)
	pygame.display.update(rect)