I have the following method that is working perfectly. Main problem I see is that I think it can be done just in one line, but I don't know how:
def _animate_display(self, display):
self._timer += 1 / bge.logic.getAverageFrameRate()
symbolic_level = self.battery.get_symbolic_level()
if self._timer >= 5.0:
self._timer = symbolic_level / 25
elif (self._timer >= 4.0) and (symbolic_level <= 100):
utils.change_texture(display, 'DisplayMat', 'icons/battery_100.png')
elif (self._timer >= 3.0) and (symbolic_level <= 75):
utils.change_texture(display, 'DisplayMat', 'icons/battery_75.png')
elif (self._timer >= 2.0) and (symbolic_level <= 50):
utils.change_texture(display, 'DisplayMat', 'icons/battery_50.png')
elif (self._timer >= 1.0) and (symbolic_level <= 25):
utils.change_texture(display, 'DisplayMat', 'icons/battery_25.png')
elif (self._timer >= 0.0) and (symbolic_level <= 0):
utils.change_texture(display, 'DisplayMat', 'icons/battery_0.png')
It models a simple animation of a charging battery in steps of 1 second. Something like: [....] --1s--> [=...] --1s--> [==..] --1s--> [===.] --1s--> [====] --1s--> [....] ...
Symbolic level is a variable that keep a value of [0, 25, 50, 75, 100], one of these, so animation loops from that symbolic value so it doesn't start from 0.