【发布时间】:2022-12-11 07:08:32
【问题描述】:
我已经实现了子弹与坦克碰撞时的无敌/免疫部分,现在我希望精灵在免疫时“闪烁”/不透明/不可见。这是我想在坦克图像中实现更改的相关代码和 TODO。
class Tank(GamePhysicsObject):
# Handle respawn
self.time_since_death = pygame.time.get_ticks()
self.immune = False
self.immune_time = 3000
def collision_bullet_tank(arb, space, data):
# Set immunity, save time since death, start flashing
tank.parent.immune = True
tank.parent.time_since_death = pygame.time.get_ticks()
tank.parent.start_flashing()
def post_update(self):
# If tank has been immune for some time, make tank vulnerable again
current_time = pygame.time.get_ticks()
if current_time - self.time_since_death > self.immune_time:
self.immune = False
# TODO: Stop flashing
基本上,我的问题是如何改变视觉精灵?
编辑:更具体地说,我在这里输入什么?
def start_flashing(self):
""" Call this function to make the tank flash. """
#TODO: White layer opacity 50% ?
1
【问题讨论】:
-
您可以使用变量进行闪烁,例如
isFlashActive,然后使用纯白色图层相应地设置它们的性质,isFlashActive的不透明度为 100% 为真,0% 为假值。 -
isFlashActive等同于 Tank 类的immune。我的问题是在这种情况下如何在水箱上方创建一个白色层?