Pygame:设置一个从表面擦除的圆圈

时间:2015-03-29 03:01:19

标签: python pygame

我有一个复杂的问题,我想我想知道是否有人可以帮助我。对于我正在进行的游戏,我需要一场战争迷雾,其中只有某些点不会被黑暗覆盖,我认为最好的方法是设置一个填充(0,0,0)到给它黑暗,然后以某种方式存在第二个表面从第一个表面擦除,并显示下面的一切。

有没有办法可以做到这一点?

1 个答案:

答案 0 :(得分:1)

import pygame
pygame.init()    

display = (1280,720)
screen = pygame.display.set_mode(display, 0, 32)
screen.fill((255,255,255)) # Fill the screen white so you can see when fog of war is lifted
fog_of_war = pygame.Surface(display)
fog_of_war.fill((0,0,0)) # creates surface size of the display and fills it black, nothing can be seen.
pygame.draw.circle(fog_of_war,(60,60,60),(200,200),100,0)
fog_of_war.set_colorkey((60,60,60)) #This is the important part, first we drew a circle on the fog of war with a certain color which we now set to transparent.
screen.blit(fog_of_war,(0,0))
pygame.display.update()

所以你在问题中想到的过程就可以了。在你的fog_of_war表面上想要拥有视觉的任何地方,只需用你设置为透明的颜色绘制一些东西,你就可以在任意多个地方做到这一点。