我在我的游戏中创建了一个日夜循环,方法是在屏幕上绘制一个矩形并让它的 alpha 不断变化。但是,我显然想为游戏添加一些光照。有没有办法使用pygame将矩形特定部分的alpha设置为0?或者是否有另一种方式来处理整个照明问题?
这就是我的白天循环的工作方式(它很糟糕,夜晚更长,但它仅用于测试):
#Setting up lighting
game_alpha = 4 #Keeping it simple for now
game_time = 15300
time_increment = -1
alpha_increment = 1
#Main Game Loop:
if float(game_time)%game_alpha == 0:
game_alpha += alpha_increment
print "Game Alpha: ",game_alpha
print "Game Time: ", game_time
if game_time < 0:
time_increment = 1
alpha_increment = -1
elif game_time >= 15300:
time_increment = -1
alpha_increment = 1
game_shadow = pygame.Surface((640, 640))
game_shadow.fill(pygame.Color(0, 0, 0))
game_shadow.set_alpha(game_alpha)
game_shadow.convert_alpha()
screen.blit(game_shadow, (0, 0))